Mark Gandolfo
2010-Jan-14 21:25 UTC
Is there a simply way to check if two models are associated?
Hey guys, I spent last night trawling through the rails API looking for some sort of @object1.associated_with?(@object2) and couldn''t find anything, but it seems so fundamental.. Does anything like this exist? if not, i might build a simple plugin/gem to mimic this behaviour. Mark -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Jan-15 13:58 UTC
Re: Is there a simply way to check if two models are associa
Mark Y g wrote:> Hey guys, > > I spent last night trawling through the rails API looking for some > sort of @object1.associated_with?(@object2) and couldn''t find > anything, but it seems so fundamental.. Does anything like this > exist?Sure. Assuming you have your associations set up properly (for example, User has_many :posts), you could do @post.user == @user or @user.posts.include? @post.> > if not, i might build a simple plugin/gem to mimic this behaviour. > > MarkBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. --0022158df84f7c53da047d3464f2 Content-Type: text/plain; charset=ISO-8859-1 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. --0022158df84f7c53da047d3464f2--