# How to represent join tables with Rails 2.3 nested attributes?

**URL:** <https://www.ruby-forum.com/t/how-to-represent-join-tables-with-rails-2-3-nested-attributes/163340>\
**Category:** Rails\
**Created:** [March 19, 2009, 1:20pm UTC](https://www.ruby-forum.com/t/how-to-represent-join-tables-with-rails-2-3-nested-attributes/163340 "2009-03-19T13:20:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![carpeliam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e19adc/32.png) [@carpeliam](https://www.ruby-forum.com/u/carpeliam)\
**Post date:** [March 19, 2009, 1:20pm UTC](https://www.ruby-forum.com/t/how-to-represent-join-tables-with-rails-2-3-nested-attributes/163340/1 "2009-03-19T13:20:15Z")

</div>

I have a model Store with a relationship Address. Because multiple  
models have relationships to Address, I have a addresses\_stores join  
table with a corresponding StoreAddress class that contains  
information specific to that store/address (store hours, phone #,  
etc).

This seemed like the way to go when I was designing the DB, but now  
that I’m dealing with Rails’ nested\_attributes, it doesn’t look like  
it’s going to work. I’m trying to link each StoreAddress to its  
corresponding Address like so:

[http://pastie.org/420843](http://pastie.org/420843)

You can see that on line 19, I’m calling fields\_for(:store\_addresses)  
and passing a StoreAddress that should be linked to a corresponding  
Address. The problem is, I don’t know how to link the StoreAddress to  
the Address if the Address itself is a new record. Even if this were  
to work, I’m not sure exactly what params would have to look like so  
that StoreAddress objects were linked with corresponding Address  
objects, considering the fact that multiple addresses can be submitted  
in the form.

So, first question is, what does params have to look like so that I  
can submit StoreAddress objects right alongside Address objects in a  
Store form. Second question is, how do I get my form to submit those  
params.

Any suggestions would be great. 🙂
