# Problem with two relationships to the same table

**URL:** <https://www.ruby-forum.com/t/problem-with-two-relationships-to-the-same-table/124076>\
**Category:** Rails\
**Created:** [December 24, 2007, 12:31pm UTC](https://www.ruby-forum.com/t/problem-with-two-relationships-to-the-same-table/124076 "2007-12-24T12:31:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rakoon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5fc32e/32.png) [@rakoon](https://www.ruby-forum.com/u/rakoon)\
**Post date:** [December 24, 2007, 12:31pm UTC](https://www.ruby-forum.com/t/problem-with-two-relationships-to-the-same-table/124076/1 "2007-12-24T12:31:40Z")

</div>

Hi all,

When I try to save a form with two collection\_select I get this error:

ActiveRecord::AssociationTypeMismatch in InscripcionController#create  
Profesion expected, got String

I think that the relationship between elements is well defined, but in  
this case I have two relationships leading to the same table (one for  
the father and one for the mother):

class Profesion \< ActiveRecord::Base  
has\_many :titulars\_padre, :class\_name=\> “Titular”, :foreign\_key =\>  
“profesion\_padre\_id”  
has\_many :titulars\_madre, :class\_name=\> “Titular”, :foreign\_key =\>  
“profesion\_madre\_id”  
end

class Titular \< ActiveRecord::Base  
has\_many :alumnos  
belongs\_to :profesion\_padre, :class\_name=\> “Profesion”, :foreign\_key  
=\> “profesion\_padre\_id”  
belongs\_to :profesion\_madre, :class\_name=\> “Profesion”, :foreign\_key  
=\> “profesion\_madre\_id”  
end

I get the error when the execution reach this point:  
t=Titular.new(params[:titular])

The params of the request are:

Request  
Parameters: {“commit”=\>“Create”, “titular”=\>{“profesion\_padre”=\>“10”,  
“profesion\_madre”=\>“4”}}

Thanks in advance

---

<div class="post-metadata">

**Author:** ![rakoon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5fc32e/32.png) [@rakoon](https://www.ruby-forum.com/u/rakoon)\
**Post date:** [December 24, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/problem-with-two-relationships-to-the-same-table/124076/2 "2007-12-24T16:57:58Z")

</div>

Rakoon Smith wrote:

> ```
> t=Titular.new(params[:titular])
> 
> ```
> 
> The params of the request are:
> 
> Request  
> Parameters: {“commit”=\>“Create”, “titular”=\>{“profesion\_padre”=\>“10”,  
> “profesion\_madre”=\>“4”}}

The select helpers in your view should be

\<%= select :titular, :profesion\_padre\_id %\> and  
\<%= select :titular, :profesion\_madre\_id %\>, not  
\<%= select :titular, :profesion\_padre %\> and  
\<%= select :titular, :profesion\_madre %\>.

–  
We develop, watch us RoR, in numbers too big to ignore.
