Enrico Teotti
2005-May-04  15:20 UTC
defining a new association I get ActiveRecord::AssociationTypeMismatch
I need to add a second client id fkey association in tabel bills. And
I need to get MyObject.second_client.name inside Rails. Right now I do
it on MyObject.client.name.
In the Bills model I''ve defined
belongs_to :client
and I''ve added:
belongs_to :second_client, :class_name => "Client", :foreign_key
=>
"second_client_id"
when I do an update I get  ActiveRecord::AssociationTypeMismatch
Client expected, got String
I do the update via this rhtml code:
 <%= select_tag("bills[second_client]",
options_from_collection_for_select(@clientList,"id","name"),
                                "class" => "standard")
%>
its inside a form that call an action doing an update_attributes.
I know bills[second_client] is a string but... when I will show this
item I will need to call MyObject.second_client.name as I aready do
with MyObject.client.name
Maybe I''m missing something on the associations cause I can''t
find the
difference between client and second_client. Someone can help me
please? Thanks,
Enrico
-- 
"The only thing necessary for the triumph of evil
is for good men to do nothing"
 Edmund Burke
Pat Mac
2005-May-05  15:15 UTC
Re: defining a new association I get ActiveRecord::AssociationTypeMismatch
On 5/4/05, Enrico Teotti <agenteo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I need to add a second client id fkey association in tabel bills. And > I need to get MyObject.second_client.name inside Rails. Right now I do > it on MyObject.client.name. > In the Bills model I''ve defined > belongs_to :client > and I''ve added: > belongs_to :second_client, :class_name => "Client", :foreign_key => > "second_client_id" > > when I do an update I get ActiveRecord::AssociationTypeMismatch > Client expected, got String > I do the update via this rhtml code: > <%= select_tag("bills[second_client]", > options_from_collection_for_select(@clientList,"id","name"), > "class" => "standard") %> > its inside a form that call an action doing an update_attributes. > > I know bills[second_client] is a string but... when I will show this > item I will need to call MyObject.second_client.name as I aready do > with MyObject.client.name > > Maybe I''m missing something on the associations cause I can''t find the > difference between client and second_client. Someone can help me > please? Thanks, > Enrico > > -- > "The only thing necessary for the triumph of evil > is for good men to do nothing" > Edmund Burke > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >It''s in the name of your select:> <%= select_tag("bills[second_client]",shoud be: <%= select_tag("bills[second_client_id]", This has something to do with Rails confusing objects & database fields but I couldn''t tell you exactly what.