Alex Smith wrote:
> Hey guys I'm having a little trouble what I think should be a pretty
> simple relationship between tables.
>
> Player.rating is a f-key to Rating.id, both fields are integers
>
> When I try to add a new player I get this error message
>
> ActiveRecord::AssociationTypeMismatch in PlayersController#create
> Rating(#38968656) expected, got String(#19165136)
>
> In my form I have this for the rating dropdown
> f.select :rating, options_for_select(Rating.all.map { |r| [r.level,
> r.id] })
>
> In my models I have
>
> #player
> has_one :rating
>
> #rating
> belongs_to :player, :foreign_key => "id"
You've got it backwards. foreign_key gives the name of the key on the
other table, so in this case, it would be 'rating', not 'id'. But why
not follow the Rails conventions, call the column Player.rating_id , and
drop the foreign key clause?
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.