# How to use has\_many and belongs\_to?

**URL:** <https://www.ruby-forum.com/t/how-to-use-has-many-and-belongs-to/153539>\
**Category:** Rails\
**Created:** [November 18, 2008, 3:02pm UTC](https://www.ruby-forum.com/t/how-to-use-has-many-and-belongs-to/153539 "2008-11-18T15:02:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BoBKilla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/779978/32.png) [@BoBKilla](https://www.ruby-forum.com/u/BoBKilla)\
**Post date:** [November 18, 2008, 3:02pm UTC](https://www.ruby-forum.com/t/how-to-use-has-many-and-belongs-to/153539/1 "2008-11-18T15:02:17Z")

</div>

Hello there,  
im kind of a newbie with ruby on rails and i have a question about  
has\_many and belongs\_to because i saw tutorials where they use it but  
i don’t see how it works ? What if you don’t use it ?  
In fact i don’t see if it is actually usefull…

Please give me some light =)

---

<div class="post-metadata">

**Author:** ![BoBKilla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/779978/32.png) [@BoBKilla](https://www.ruby-forum.com/u/BoBKilla)\
**Post date:** [November 18, 2008, 3:05pm UTC](https://www.ruby-forum.com/t/how-to-use-has-many-and-belongs-to/153539/2 "2008-11-18T15:05:02Z")

</div>

has\_many / belongs\_to is how you tell Rails that models are related…

Start reading here:

[http://api.rubyonrails.org/](http://api.rubyonrails.org/)

Look at the ActiveRecord::Base entry to begin your instruction  
Grasshopper…

---

<div class="post-metadata">

**Author:** ![BoBKilla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/779978/32.png) [@BoBKilla](https://www.ruby-forum.com/u/BoBKilla)\
**Post date:** [November 18, 2008, 3:06pm UTC](https://www.ruby-forum.com/t/how-to-use-has-many-and-belongs-to/153539/3 "2008-11-18T15:06:25Z")

</div>

On 18 Nov 2008, at 12:51, BoBKilla wrote:

> Hello there,  
> im kind of a newbie with ruby on rails and i have a question about  
> has\_many and belongs\_to because i saw tutorials where they use it but  
> i don’t see how it works ? What if you don’t use it ?  
> In fact i don’t see if it is actually usefull…

Well associations are pretty fundamental to Active Record. You don’t  
have to use them but you’d just be creating a lot of work for yourself  
and missing out on a lot of the handy bits in rails.  
[rails.info](http://guides.rails.info/association_basics.html) is probably not a bad  
place to start.

Fred

---

<div class="post-metadata">

**Author:** ![BoBKilla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/779978/32.png) [@BoBKilla](https://www.ruby-forum.com/u/BoBKilla)\
**Post date:** [November 19, 2008, 10:24am UTC](https://www.ruby-forum.com/t/how-to-use-has-many-and-belongs-to/153539/4 "2008-11-19T10:24:25Z")

</div>

thanks, now i see why it is usefull to use it !
