This is my current table setup:
WINES
id…etc. etc.
AWARDS
id, wine_id, competition_id, medal_id, date, link
COMPETITIONS
id, name
MEDALS
id, type
Award > belongs_to :wine
Wine > has_many :awards, :autosave => true, :dependant => :destroy
That’s all well and fine, but I’d like to be able to reference the ‘name’ and ‘type’ columns for each award’s competition and medal. Currently I can only see ‘competition_id’ and ‘medal_id’…I’d like to be able to say ‘@wine.awards[0].medal’ which would result in “Gold”…or even ‘medal_type’ for that matter. How would I set up that association in my model?
If I understood well, using this relation:
so you can say @wind.awards[0].medal.type and have “Gold” as result. Every relation must be defined, so you have also to add
So you can to @wine.awards[0].competition.name
And also the backwards relation are important.