# Two fields associated to the same table

**URL:** <https://www.ruby-forum.com/t/two-fields-associated-to-the-same-table/111574>\
**Category:** Rails\
**Created:** [August 8, 2007, 7:05pm UTC](https://www.ruby-forum.com/t/two-fields-associated-to-the-same-table/111574 "2007-08-08T19:05:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@coelho](https://www.ruby-forum.com/u/coelho)\
**Post date:** [August 8, 2007, 7:05pm UTC](https://www.ruby-forum.com/t/two-fields-associated-to-the-same-table/111574/1 "2007-08-08T19:05:37Z")

</div>

Hello,

I have a model that contains two fields associated with the same table,  
I hooked one up using the standard has\_many association but I have no  
clue on how to do the second one.  
here are my models

class Task \< ActiveRecord::Base  
belongs\_to :user #works fine associating through the user\_id field in  
the table

# belongs\_to :user2

#I don’t know what to place here, but I need to associate field  
resquester\_id to #the users tables too

end

class User \< ActiveRecord::Base  
has\_many :tasks  
end

appreciate any help  
Coelho

---

<div class="post-metadata">

**Author:** ![coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@coelho](https://www.ruby-forum.com/u/coelho)\
**Post date:** [August 8, 2007, 7:24pm UTC](https://www.ruby-forum.com/t/two-fields-associated-to-the-same-table/111574/2 "2007-08-08T19:24:35Z")

</div>

you need 2 foriegn keys. Then add the :foriegn\_key =\> :user2\_id to  
has\_many and belongs\_to

On Aug 8, 1:05 pm, coelho coelho [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
