0

我刚刚安装了acts_as_taggable_on 插件,我正在尝试做

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

如您所见,我想将 find() 方法与其他 2 个模型(产品、点、标签)一起使用。我想在 :condition => {} 属性中使用所有 3 个模型。

有没有可能。我应该怎么办?

4

2 回答 2

0

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
于 2010-01-01T23:01:40.777 回答
0

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']})
于 2010-01-01T23:24:45.037 回答