# Issues with relationships and multiple objects on one form

**URL:** <https://www.ruby-forum.com/t/issues-with-relationships-and-multiple-objects-on-one-form/102183>\
**Category:** Rails\
**Created:** [August 12, 2006, 8:46am UTC](https://www.ruby-forum.com/t/issues-with-relationships-and-multiple-objects-on-one-form/102183 "2006-08-12T08:46:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_Muench](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9dc877/32.png) [@Dave\_Muench](https://www.ruby-forum.com/u/Dave_Muench)\
**Post date:** [August 12, 2006, 8:46am UTC](https://www.ruby-forum.com/t/issues-with-relationships-and-multiple-objects-on-one-form/102183/1 "2006-08-12T08:46:27Z")

</div>

Hello,

1. I have a form that edits a User and a Person at the same time. The  
controller is for the User. Everything works fine, except the fields  
that are populated by the Person fields lose state when validation  
fails. Do I use params to populate the user? I have tried a bunch of  
combinations with no luck.

2. The same users table has an integer column called  
‘primary\_organization\_id’, where Organization references many User  
records. The models are defined as:

class User \< ActiveRecord::Base  
belongs\_to :primary\_organization,  
:class\_name =\> ‘Organization’,  
:foreign\_key =\> ‘primary\_organization\_id’

class Organization \< ActiveRecord::Base  
has\_many :primary\_users,  
:class\_name =\> ‘User’,  
:foreign\_key =\> ‘primary\_organization\_id’

A select displays all Organizations on the User form, allowing the  
relationship to be defined using the code:

Primary Organization \<%= collection\_select('user', 'primary\_organization\_id', @organizations, 'id', 'name') %\>

When I create and save a new user everything works fine. When I open  
the user to edit it, the relationship is correct, but when I try and  
save existing user I get the error:

Unknown key(s): primary\_organization\_id

Any help would be greatly appreciated.

Thanks,  
Dave
