# Multiple belongs\_to a single model

**URL:** <https://www.ruby-forum.com/t/multiple-belongs-to-a-single-model/134022>\
**Category:** Rails\
**Created:** [April 6, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/multiple-belongs-to-a-single-model/134022 "2008-04-06T23:25:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rashantha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@rashantha](https://www.ruby-forum.com/u/rashantha)\
**Post date:** [April 6, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/multiple-belongs-to-a-single-model/134022/1 "2008-04-06T23:25:14Z")

</div>

i came across this post by s.ross and i am having a similar problem.  
but mine is related to output.

\<[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/)  
3f3a0f4b1e8ab157/e5d055c888a155da?lnk=gst&q=multiple  
+belongs\_to#e5d055c888a155da\>

in his example his he has multiple associations

```
 class Bug < ActiveRecord::Base
    belongs_to :reporter, :class_name=>'User', :foreign_key =>

```

‘reporter\_id’  
belongs\_to :assignee, :class\_name=\>‘User’, :foreign\_key =\>  
‘assigned\_to\_id’

everything works great, in console but in the app.

@bugs = Bug.find :all  
for errors in @bugs  
errors.date - no problem works fine  
errors.reporter.name - gets an error  
errors[45].reporter.name - works fine

what am i doing wrong

this works in console  
ie:

@bugs = Bug.find :all  
one\_error = @bugs[45]  
one\_error.date (good)  
one\_error.reporter.name (good)  
one\_error.assignee.name (good)

it has to be something simple. tia

---

<div class="post-metadata">

**Author:** ![rashantha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@rashantha](https://www.ruby-forum.com/u/rashantha)\
**Post date:** [April 7, 2008, 4:45am UTC](https://www.ruby-forum.com/t/multiple-belongs-to-a-single-model/134022/2 "2008-04-07T04:45:51Z")

</div>

does anyone have an idea on this.

i have check all the capitalization

variable.association.assocation\_variable

i really need some pointers on this.

---

<div class="post-metadata">

**Author:** ![rashantha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@rashantha](https://www.ruby-forum.com/u/rashantha)\
**Post date:** [April 7, 2008, 6:05am UTC](https://www.ruby-forum.com/t/multiple-belongs-to-a-single-model/134022/3 "2008-04-07T06:05:17Z")

</div>

Can you give us a concrete version of it, rather than this abstract  
version?

Julian.

Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) VIDEO #3  
OUT APRIL 6  
[http://sensei.zenunit.com/](http://sensei.zenunit.com/)
