Rails 3 - association according own table column -


i have these 2 tables:

colors - id - name - name_code  cars - id - manufacturer - color_code_name 

(in columns colors.name_code , cars.color_code_name same values)

i cars respective color. tried set these associations:

class color < activerecord::base   has_many :cars, :primary_key => "name_code" end class car < activerecord::base   belongs_to :color, :primary_key => "color_code_name" end 

but unfortunately doesn't working... didn't specify yet kind of association, not sure, if it's possible it...

i gonna grateful every advise

try this:

class color < activerecord::base   self.primary_key :name_code   has_many :cars, :foreign_key => :color_code_name end  class car < activerecord::base   self.primary_key :color_code_name   belongs_to :color, :foreign_key => :color_code_name end 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -