Hi, When using acts as taggable on steroids, you can search a model''s tags by doing somthing like Post.find_tagged_with(''Funny, Silly'') But how do you search all tags without using manual sql and not limit it just to one model? thanks -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Hi,> When using acts as taggable on steroids, you can search a model''s tags > But how do you search all tags without using manual sql and not limit it > just to one model? >When you install the plugin you have the taggings table and the corresponding Tagging model. Tagging is related to the model Tag. So, you could do something like Tagging.find(:all,:include=>:tag,:conditions=>[''tags.name in (?)'',tags_to_search]) That will give you all the taggings, having the model name in the "taggable_type" attribute and the id in the taggable_id field. Moreover, Tagging has a polymorphic reference to :taggable, meaning you could directly get the related objet directly by invoking .taggable over any of the row results. Just be aware you''ll be launching a new query for each row if you do so since as far as I know you cannot eager load a polymorphic association. Regards, javier ramÃrez --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the comments above, this is how I have done it. My concern at the minute is the 21 database queries that need to made to get the results required. Has anyone got any comments on how this can be optimized? Thanks # # searchers all taggable types def do_all_search(ps_condition, ps_page) initial_results = Tagging.paginate(:all, :include=>[:tag], :conditions=>[''tags.name in (?)'', ps_condition], :page => ps_page, :per_page => 20) actual_result = Array.new initial_results.each do |tag_result| actual_result << tag_result.taggable.class.find(tag_result.taggable.id) end return actual_result, initial_results end -- 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?hl=en -~----------~----~----~----~------~----~------~--~---