# Difference between has\_one and belongs\_to

**URL:** <https://www.ruby-forum.com/t/difference-between-has-one-and-belongs-to/120692>\
**Category:** Rails\
**Created:** [November 19, 2007, 9:10pm UTC](https://www.ruby-forum.com/t/difference-between-has-one-and-belongs-to/120692 "2007-11-19T21:10:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [November 19, 2007, 9:10pm UTC](https://www.ruby-forum.com/t/difference-between-has-one-and-belongs-to/120692/1 "2007-11-19T21:10:32Z")

</div>

Is the difference between has\_one and \_belongs\_to that with has\_one you  
can use the additional parameters such as :dependent and :order? Or is  
there more to it then that? Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [November 19, 2007, 9:35pm UTC](https://www.ruby-forum.com/t/difference-between-has-one-and-belongs-to/120692/2 "2007-11-19T21:35:43Z")

</div>

On 19 Nov 2007, at 20:10, Shandy N. wrote:

> Is the difference between has\_one and \_belongs\_to that with has\_one  
> you  
> can use the additional parameters such as :dependent and :order? Or is  
> there more to it then that? Thanks,

It’s about where the foreign key sits.

class Foo \< AR:Base  
end

if foo belongs\_to :bar, then the foos table has a bar\_id column  
if foo has\_one :bar,then the bars table has a foo\_id column

Fred

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [November 20, 2007, 1:51pm UTC](https://www.ruby-forum.com/t/difference-between-has-one-and-belongs-to/120692/3 "2007-11-20T13:51:43Z")

</div>

On the conceptual level, if your class A has a has\_one relationship  
with class B then class A is the parent of class B hence your class B  
will have a belongs\_to relationship with class A since it is the child  
of class A.

This is the reason (as Fred specified before), you will have a\_id as  
foriegn key in your table b

On Nov 19, 8:10 pm, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
