I have these two tables:
colors
- id
- name
- name_code
cars
- id
- manufacturer
- color_code_name
(in the columns colors.name_code and cars.color_code_name are the same values)
I would like to get all cars with the respective color. I tried to set up 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 this is unfortunately doesn’t working… I didn’t specify yet this kind of association, so I am not really sure, if it’s possible to do it…
I am gonna be grateful for every advise
Try this: