# Convention for setting join model fields when associating

**URL:** <https://www.ruby-forum.com/t/convention-for-setting-join-model-fields-when-associating/166392>\
**Category:** Rails\
**Created:** [April 24, 2009, 6:00pm UTC](https://www.ruby-forum.com/t/convention-for-setting-join-model-fields-when-associating/166392 "2009-04-24T18:00:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [April 24, 2009, 6:00pm UTC](https://www.ruby-forum.com/t/convention-for-setting-join-model-fields-when-associating/166392/1 "2009-04-24T18:00:34Z")

</div>

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
