# Has\_one relationship problem

**URL:** <https://www.ruby-forum.com/t/has-one-relationship-problem/52332>\
**Category:** Rails\
**Created:** [January 12, 2006, 9:45pm UTC](https://www.ruby-forum.com/t/has-one-relationship-problem/52332 "2006-01-12T21:45:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raja\_Bhatia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@Raja\_Bhatia](https://www.ruby-forum.com/u/Raja_Bhatia)\
**Post date:** [January 12, 2006, 9:45pm UTC](https://www.ruby-forum.com/t/has-one-relationship-problem/52332/1 "2006-01-12T21:45:46Z")

</div>

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.

[http://www.rafb.net/paste/results/GSBt1e61.html](http://www.rafb.net/paste/results/GSBt1e61.html)

Thanks,

r.b

---

<div class="post-metadata">

**Author:** ![Raja\_Bhatia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@Raja\_Bhatia](https://www.ruby-forum.com/u/Raja_Bhatia)\
**Post date:** [January 12, 2006, 9:54pm UTC](https://www.ruby-forum.com/t/has-one-relationship-problem/52332/2 "2006-01-12T21:54:55Z")

</div>

What you describe should be fine, so the problem must be somewhere else.  
Do  
you have your selection table setup with a user\_id field?

matt

---

<div class="post-metadata">

**Author:** ![Raja\_Bhatia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@Raja\_Bhatia](https://www.ruby-forum.com/u/Raja_Bhatia)\
**Post date:** [January 12, 2006, 10:25pm UTC](https://www.ruby-forum.com/t/has-one-relationship-problem/52332/3 "2006-01-12T22:25:14Z")

</div>

yes, the selections table has a user\_id field

---

<div class="post-metadata">

**Author:** ![Raja\_Bhatia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@Raja\_Bhatia](https://www.ruby-forum.com/u/Raja_Bhatia)\
**Post date:** [January 12, 2006, 11:14pm UTC](https://www.ruby-forum.com/t/has-one-relationship-problem/52332/4 "2006-01-12T23:14:07Z")

</div>

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 = Selection.new

---

<div class="post-metadata">

**Author:** ![Raja\_Bhatia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@Raja\_Bhatia](https://www.ruby-forum.com/u/Raja_Bhatia)\
**Post date:** [January 13, 2006, 6:16pm UTC](https://www.ruby-forum.com/t/has-one-relationship-problem/52332/5 "2006-01-13T18:16:53Z")

</div>

is that necessary?

I was under the assumption that the model relationships would handle  
the collection?
