# Two belongs\_to relationship

**URL:** <https://www.ruby-forum.com/t/two-belongs-to-relationship/154185>\
**Category:** Rails\
**Created:** [November 26, 2008, 8:34am UTC](https://www.ruby-forum.com/t/two-belongs-to-relationship/154185 "2008-11-26T08:34:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [November 26, 2008, 8:34am UTC](https://www.ruby-forum.com/t/two-belongs-to-relationship/154185/1 "2008-11-26T08:34:50Z")

</div>

I have three models:User,Action,Comment.User have has\_many relation  
with the Action,this is true.A user can make many comments for  
different action,an action can have many comments belonging to it.So  
can i use two has many and two belongs\_to to set the relationship  
among the three models like following?  
has\_many :comments in User model  
has\_many :comments in Action model  
belongs\_to :user  
belongs\_to :action in the Comment model.

That is the Comment has two foreign keys.

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [November 26, 2008, 11:01am UTC](https://www.ruby-forum.com/t/two-belongs-to-relationship/154185/2 "2008-11-26T11:01:00Z")

</div>

On Nov 26, 8:34 am, daociyiyou [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> That is the Comment has two foreign keys.  
> Sure, that’s no problem. The Comments belong to a User and an Action  
> That’s a quite common thing, lots of comments, blog entries or similar  
> things belong to Users and any kind of List, Group or whatever.

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [November 27, 2008, 1:40am UTC](https://www.ruby-forum.com/t/two-belongs-to-relationship/154185/3 "2008-11-27T01:40:34Z")

</div>

Thank you!
