开发者

Rails acts_as_taggable_on multiple tables

I just installed acts_as_taggable_on plugin and I'm trying to do

@products开发者_Go百科 = Product.find(:all, :include => [:points, :tags], :conditions => '...', :tags => 'tag1, tag2')

As you can see I would like to use find() method with 2 other models (Product,Point,Tag). I would like to use all 3 models in a :condition => {} attribute.

Is it posible. What should I do?


Why don't you just merge the results?

@results = []
%W(Product Point Tag).each do |model|
  @results += model.constantize.find(:all, :include => [:points, :tags], :conditions => '...', :tags => 'tag1, tag2')
end


I think you're asking how to use multiple models in a conditions hash for find. Something like this should work.

@products = Product.find(:all, :include => [:points, :tags], :conditions => {:points=>{:value=>5}, :tags=>['tag1','tag2']})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜