# How to get two "has\_a" relationships to the same table?

**URL:** <https://www.ruby-forum.com/t/how-to-get-two-has-a-relationships-to-the-same-table/48388>\
**Category:** Rails\
**Created:** [November 19, 2005, 7:39pm UTC](https://www.ruby-forum.com/t/how-to-get-two-has-a-relationships-to-the-same-table/48388 "2005-11-19T19:39:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [November 19, 2005, 7:39pm UTC](https://www.ruby-forum.com/t/how-to-get-two-has-a-relationships-to-the-same-table/48388/1 "2005-11-19T19:39:04Z")

</div>

I have an audit table with fields auditor\_id and manager\_id that both  
link to the people table:

AUDIT:  
id  
name  
datecreated  
auditor\_id  
manager\_id

PEOPLE:  
id  
name

I have no idea how to link both fields from audit to people?? any  
ideas??  
I’m pulling my hair out trying to figure this out, please help!!

I know that if it were just one field then i’d call the field person\_id.

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [November 19, 2005, 7:43pm UTC](https://www.ruby-forum.com/t/how-to-get-two-has-a-relationships-to-the-same-table/48388/2 "2005-11-19T19:43:25Z")

</div>

Sorry i meant “has\_one” not “has\_a”.

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [November 19, 2005, 7:57pm UTC](https://www.ruby-forum.com/t/how-to-get-two-has-a-relationships-to-the-same-table/48388/3 "2005-11-19T19:57:19Z")

</div>

You probably want something like this:

class Audit \< ActiveRecord::Base  
belongs\_to :auditor, :class\_name =\> ‘Person’, :foreign\_key =\>  
‘auditor\_id’  
belongs\_to :manager, :class\_name =\> ‘Person’, :foreign\_key =\>  
‘manager\_id’  
end

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [December 7, 2005, 12:55am UTC](https://www.ruby-forum.com/t/how-to-get-two-has-a-relationships-to-the-same-table/48388/4 "2005-12-07T00:55:22Z")

</div>

Awesome I was trying to figure this exact same thing out and this worked  
perfectly, thanks.
