postgresql - Rails inconsistent model associations call -


i have rails model user as:

class player < activerecord::base   has_and_belongs_to_many :character_factors   has_and_belongs_to_many :stats_factors end 

and character factors model as:

class characterfactor < activerecord::base   has_and_belongs_to_many :players end 

and stats factors model is:

class statfactor < activerecord::base   has_and_belongs_to_many :players end 

within player model have following methods:

def self.character_factors(id)   @character_factors = characterfactor.joins(:players).where('players.id = ?', id) end 

and method:

def self.stat_factors(id)   @stat_factors = statfactor.joins(:players).where('players.id = ?', id) end 

the join on character factors , players looks correct table:

players_character_factors , performs query properly

whereas join on stat_factors looks table:

stat_factors_players , errors out. i'm not sure why looks 2 differently formatted table names exact same association. there i'm not doing correctly on here?

i found solution question.

in rails habtm associations table names generated automatically in lexical order of model names unless explicitly specified.

in case since didn't specify name of join table tables rails trying wrong. fixed updating models such:

class player < activerecord::base   has_and_belongs_to_many :character_factors, :join_table => :players_character_factors   has_and_belongs_to_many :stats_factors, :join_table => :players_stats_factors end 

and character factors:

class characterfactor < activerecord::base   has_and_belongs_to_many :players, :join_table => :players_character_factors end 

and stat factors:

class statfactor < activerecord::base   has_and_belongs_to_many :players, :join_table => :players_stats_factors end 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -