# Defining A model that have two has\_many

**URL:** <https://www.ruby-forum.com/t/defining-a-model-that-have-two-has-many/158064>\
**Category:** Rails\
**Created:** [January 18, 2009, 11:34pm UTC](https://www.ruby-forum.com/t/defining-a-model-that-have-two-has-many/158064 "2009-01-18T23:34:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![builtbysimple](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/aca169/32.png) [@builtbysimple](https://www.ruby-forum.com/u/builtbysimple)\
**Post date:** [January 18, 2009, 11:34pm UTC](https://www.ruby-forum.com/t/defining-a-model-that-have-two-has-many/158064/1 "2009-01-18T23:34:09Z")

</div>

Dear all,

I am currently confused with defining model in Rails that has two  
has\_many relationship.

I have a model that is called Category, and this model will be used by  
two model which is Product and Blog.

Would this definition make sense in rails ?

Category  
has\_many :product  
has\_many :blog

Product  
belongs\_to :category

Blog  
belongs\_to :category

Or is there a better way to do it in Rails?

Thanks for the hint.

–  
Not by might nor by power, but by His Spirit.

Read my blog: [http://joshuajava.wordpress.com/](http://joshuajava.wordpress.com/)  
Follow me on twitter: [http://twitter.com/jpartogi](http://twitter.com/jpartogi)

---

<div class="post-metadata">

**Author:** ![builtbysimple](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/aca169/32.png) [@builtbysimple](https://www.ruby-forum.com/u/builtbysimple)\
**Post date:** [January 18, 2009, 11:40pm UTC](https://www.ruby-forum.com/t/defining-a-model-that-have-two-has-many/158064/2 "2009-01-18T23:40:01Z")

</div>

On 18 Jan 2009, at 22:33, Joshua P. wrote:

> Category  
> has\_many :product  
> has\_many :blog

has\_many indicates a plural ie it should be has\_many :products.  
Other than that from a pure rails point of view it makes sense but I  
can’t tell if what that expresses corresponds to what you want.

Fred
