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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 26, 8:34 am, daociyiyou <chey...-/E1597aS9LRv1O+Z8WTAqQ@public.gmane.org> wrote:> 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.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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you! On Nov 26, 6:00 pm, Thorsten Müller <thors...-1oxKqHKwyltBDgjK7y7TUQ@public.gmane.org> wrote:> On Nov 26, 8:34 am, daociyiyou <chey...-/E1597aS9LRv1O+Z8WTAqQ@public.gmane.org> wrote: > > > 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 usetwohas many andtwobelongs_toto 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 hastwoforeign 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---