Hello everyone, I have a Model and table called ''comments.'' This table has columns ''id'', ''user_id'', ''commenter_id'', and ''message.'' I can access the user of the comment, like this "@commenter.user", but cannot access the commenter (the one who made the comment). The commenter should is the same type object as user, so polymorphism isn''t the solution. I thought that a foreign key would do the trick, but I either set up the key incorrectly, or using a foreign isn''t the solution. Is there a way to access the commenter as a User object, like @comment.commenter, without having to create a table/model called Commenter? Thanks for your time, Wild Al -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
In comment.rb belongs_to :commenter, :foreign_key => ''commenter_id'', :class_name => ''User'' That should do it. Wild Al wrote:> Hello everyone, > > I have a Model and table called ''comments.'' This table has columns > ''id'', ''user_id'', ''commenter_id'', and ''message.'' I can access the user > of the comment, like this "@commenter.user", but cannot access the > commenter (the one who made the comment). > > The commenter should is the same type object as user, so polymorphism > isn''t the solution. I thought that a foreign key would do the trick, > but I either set up the key incorrectly, or using a foreign isn''t the > solution. > > Is there a way to access the commenter as a User object, like > @comment.commenter, without having to create a table/model called > Commenter? > > Thanks for your time, > Wild Al > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
That did it, thanks a lot! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---