# Has\_one

**URL:** <https://www.ruby-forum.com/t/has-one/108227>\
**Category:** Rails\
**Created:** [June 30, 2007, 3:00pm UTC](https://www.ruby-forum.com/t/has-one/108227 "2007-06-30T15:00:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonas](https://www.ruby-forum.com/u/jonas)\
**Post date:** [June 30, 2007, 3:00pm UTC](https://www.ruby-forum.com/t/has-one/108227/1 "2007-06-30T15:00:36Z")

</div>

I got two models:

Extension and User. User has a foreign key called extension\_id.  
Extension has not key to user since it can be used by various models.

My user model has “has\_one :extension”

Why do the following code fail?  
@user = User.find(params[:id])  
@user.extension.create

Error:  
PGError: ERROR: column extensions.user\_id does not exist  
RAD 1: SELECT \* FROM extensions WHERE (extensions.user\_id = 1) LIM…  
^  
: SELECT \* FROM extensions WHERE (extensions.user\_id = 1) LIMIT 1

* * *

I do not understand why extension have to have a user\_id? Can’t  
relations be one way?

---

<div class="post-metadata">

**Author:** ![jonas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonas](https://www.ruby-forum.com/u/jonas)\
**Post date:** [June 30, 2007, 3:16pm UTC](https://www.ruby-forum.com/t/has-one/108227/2 "2007-06-30T15:16:26Z")

</div>

If the User Model has the foreign key “extension\_id” it’s not  
has\_on :extension  
it has to be  
belongs\_to :extension

foreign keys are always on the belongs\_to side. has\_one/has\_many has  
no foreign keys.
