2010-01-01 71 views
0

我刚安装acts_as_taggable_on插件,我试图做Rails的acts_as_taggable_on多个表

@products = Product.find(:全部:包括=> [:点:标签]:条件=>' ...',:tags =>'tag1,tag2')

正如你所看到的,我想使用find()方法和其他两个模型(Product,Point,Tag)。我想在a:condition => {}属性中使用所有3个模型。

它是否可行。我该怎么办?

回答

0

你为什么不合并结果?

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

我想你问的是如何在查找条件散列中使用多个模型。像这样的东西应该工作。

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

:tags =>不起作用...插件不支持这个,所以我正在寻找解决方案/解决方法。 – xpepermint 2010-01-01 23:49:39

+0

看看这个博客文章http://juixe.com/techknow/index.php/2006/07/18/acts-as-taggable-conditions-hack/它可能会给你一些想法。我不认为你可以使用基于哈希的条件来做你想做的事情,这有点太复杂。 – 2010-01-02 01:33:56