Forum: Ruby on Rails Convention for setting join model fields when associating

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Max W. (Guest)
on 2009-04-24 20:00
Hi folks

I have this situation:

  has_many :policy_indicator_allocations, :order => "position"
  has_many :policy_indicators, :through => :policy_indicator_allocations

  belongs_to :region
  belongs_to :policy_indicator
  belongs_to :year

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

  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:
    :region_id =>,
    :policy_indicator_id =>,
    :year_id => )

Is there a neater way?

This topic is locked and can not be replied to.