我刚刚安装了acts_as_taggable_on 插件,我正在尝试做
@products = Product.find(:all, :include => [:points, :tags], :conditions => '...', :tags => 'tag1, tag2')
如您所见,我想将 find() 方法与其他 2 个模型(产品、点、标签)一起使用。我想在 :condition => {} 属性中使用所有 3 个模型。
有没有可能。我应该怎么办?
我刚刚安装了acts_as_taggable_on 插件,我正在尝试做
@products = Product.find(:all, :include => [:points, :tags], :conditions => '...', :tags => 'tag1, tag2')
如您所见,我想将 find() 方法与其他 2 个模型(产品、点、标签)一起使用。我想在 :condition => {} 属性中使用所有 3 个模型。
有没有可能。我应该怎么办?
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']})