Forum: Ruby on Rails has_one relationship problem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Raja Bhatia (Guest)
on 2006-01-12 22:45
(Received via mailing list)
I was wondering if anyone could see the error in this littte application

I have two models, User and Selection

Selection is an extension of the User model

so in the User model I have a has_one :selection
and in Selection I have a belongs_to :user

in my views, i cannot get @user.selection to work but @user works fine.


matthew clark (Guest)
on 2006-01-12 22:54
(Received via mailing list)
What you describe should be fine, so the problem must be somewhere else.
you have your selection table setup with a user_id field?

Raja Bhatia (Guest)
on 2006-01-12 23:25
(Received via mailing list)
yes, the selections table has a user_id field
matthew clark (Guest)
on 2006-01-13 00:14
(Received via mailing list)
One more thing to check is to make sure that the user actually has a
selection assigned to it.  Do this in the controller-

@user.selection =
Raja Bhatia (Guest)
on 2006-01-13 19:16
(Received via mailing list)
is that necessary?

I was under the assumption that the model relationships would handle
the collection?
This topic is locked and can not be replied to.