views:

119

answers:

2

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

@products = 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?

A: 

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
vise
A: 

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']})
John Duff
:tags=> does not work... the plugin does not support this, so I'm looking for a solution/workaround.
xpepermint
Take a look at this blog post http://juixe.com/techknow/index.php/2006/07/18/acts-as-taggable-conditions-hack/ it might give you some ideas. I don't think you can use the hash based conditions for what you're trying to do, it's a little too complicated.
John Duff