# Model Releationship, belong, has?

**URL:** <https://www.ruby-forum.com/t/model-releationship-belong-has/103438>\
**Category:** Rails\
**Created:** [May 6, 2007, 1:47am UTC](https://www.ruby-forum.com/t/model-releationship-belong-has/103438 "2007-05-06T01:47:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [May 6, 2007, 1:47am UTC](https://www.ruby-forum.com/t/model-releationship-belong-has/103438/1 "2007-05-06T01:47:29Z")

</div>

Hello,

I have two models.

blog\_post  
belongs\_to :blog\_category

blog\_category  
has\_many :blog\_post

Whenever I do this, I get error (uninitialized constant  
BlogPost::BlogCategories)  
\<%= post.blog\_categories.name %\>

Post is variable which continue one row from the blog\_post table.

BUT when I write this, it works, but this is bad to have it in the view  
☹  
\<%= BlogCategory.find\_by\_id(post.blog\_category\_id).name %\>

Anyone knows why I’m getting:  
uninitialized constant BlogPost::BlogCategories?

and thanks many times 🙂

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [May 6, 2007, 2:11pm UTC](https://www.ruby-forum.com/t/model-releationship-belong-has/103438/2 "2007-05-06T14:11:18Z")

</div>

Jamal S. wrote:

> Hello,
> 
> I have two models.
> 
> blog\_post  
> belongs\_to :blog\_category
> 
> blog\_category  
> has\_many :blog\_post

Weird ?

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [May 6, 2007, 3:54pm UTC](https://www.ruby-forum.com/t/model-releationship-belong-has/103438/3 "2007-05-06T15:54:16Z")

</div>

Fixed,

it was because…

belong\_to :blog\_categories

should be

belong\_to :blog\_category

In this topic I just made a example and wrote it right 😃

Reference: [http://snippets.dzone.com/posts/show/2089](http://snippets.dzone.com/posts/show/2089)  
Google: Rails+find+include
