Forum: Ruby on Rails two belongs_to relationship

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
669c735cf55efa005140fa232b05c4f6?d=identicon&s=25 daociyiyou (Guest)
on 2008-11-26 08:34
(Received via mailing list)
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.
2d8132658d56e51f19ace1c68e48b6aa?d=identicon&s=25 Thorsten Mueller (thorsten)
on 2008-11-26 11:01
(Received via mailing list)
On Nov 26, 8:34 am, daociyiyou <chey...@yahoo.com.cn> 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.
669c735cf55efa005140fa232b05c4f6?d=identicon&s=25 daociyiyou (Guest)
on 2008-11-27 01:40
(Received via mailing list)
Thank you!
This topic is locked and can not be replied to.