i have two module both are joined by HABTM name are tags and content_masters i have content_master .id and i want to get all the content_masters which are with the same tag as that id has . means if my content_master .id=1 is associated with tag_id 1,2 than i want the listing of all the content_master with tag_id=1,2 please suggest how to do in rails thanks rahul -- 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.
On 15 April 2010 13:58, Rahul Mehta <rahul23134654-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i have two module both are joined by HABTM name are tags and > content_masters > > i have content_master .id and i want to get all the content_masters > which are with the same tag as that id has . > > means if my content_master .id=1 is associated with tag_id 1,2 > than i want the listing of all the content_master with tag_id=1,2Do you really have just the id of the content master or do you have the object itself? If you have a content_master in @content_master then the associated tags are available as an array in @content_master.tags. If you only have the id of the content master then something like @tags = Tag.find( :all, :include => ''content_masters'', :conditions => [''content_masters.id = ?'', content_master.id] ) Colin -- 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.
hello Rahul, On Apr 15, 5:58 pm, Rahul Mehta <rahul23134...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i have two module both are joined by HABTM name are tags and > content_masters> i have content_master .id and i want to get all the content_masters > which are with the same tag as that id has .if it is joined by has_and_belongs_to_many , then you can simply do this by @content_master = ContentMaster.find(1) # id= 1 is just taken as example @content_master.tag # this will give you array of all the tags that are assosiated to id 1 in the case you want reverse then @tag = Tag.find(1) # assuming tag to be a model @tag.content_master # this will give you array of all the content_master assosiated with tag_id = 1 hope this helps mac -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hii mac (manmohan ), thanks for answer you have given me the method to find out to content master listing of tag id 1 but i want the content master listing of all which are associated with tag id 1,2 please help in this regard On Apr 15, 9:16 pm, mac <care4u.jodh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hello Rahul, > > On Apr 15, 5:58 pm, Rahul Mehta <rahul23134...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > i have two module both are joined byHABTMname are tags and > > content_masters > > i have content_master .id and i want to get all the content_masters > > which are with the same tag as that id has . > > if it is joined by has_and_belongs_to_many , then you can simply do > this by > @content_master = ContentMaster.find(1) # id= 1 is just taken as > example > @content_master.tag # this will give > you array of all the tags that are assosiated to id 1 > > in the case you want reverse then > > @tag = Tag.find(1) # assuming tag to be a > model > @tag.content_master # this will give you array of > all the content_master assosiated with tag_id = 1 > > hope this helps > > mac-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
have u tried using : ContentMaster.find_by_sql("Select * From content_master where tag_id=1 AND tag_id=2") then follow the same steps for array and make loop . I suppose this should solve your problem thank you, manmohan vyas -- 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.