Convention for setting join model fields when associating


#1

Hi folks

I have this situation:

Region
has_many :policy_indicator_allocations, :order => “position”
has_many :policy_indicators, :through => :policy_indicator_allocations

PolicyIndicatorAllocation
belongs_to :region
belongs_to :policy_indicator
belongs_to :year

PolicyIndicator
has_many :policy_indicator_allocations
has_many :regions, :through => :policy_indicator_allocations

Year
has_many :policy_indicator_allocations

So, policy_indicator_allocations are joins between a region and a policy
indicator, for a particular year.

What i’m wondering is this: when i come to associate a policy indicator
with a region, i want to do it for a particular year. What’s the
best/most conventional way to do this? (assume i have the relevant
models in instance vars)

A not very clever way is this:
PolicyIndicatorAllocation.create(
:region_id => @region.id,
:policy_indicator_id => @policy_indicator.id,
:year_id => @year.id )

Is there a neater way?

thanks
max