Topic: match ALL using activerecord on an association

I need an activerecord query to Match ALL items in a params array.

My current method gives results based on finding any of the tags, not "MATCH ALL"

    class Product < ActiveRecord::Base
        has_many :tags

        def self.filter_by_params(params)
            scoped = self.scoped
            scoped = scoped.includes(:tags).where(:tags => {:id => params[:t]}) if params[:t]
            scoped
        end
    end

I was attempting to write it something like below, but it gives me no results, maybe someone can set me in the right direction. is there a way to say " AND "

    def self.filter_by_params(params)
        scoped = self.scoped.includes(:tags)
        params[:t].each do |t|
            scoped = scoped.where(:tags => {:id => t})
        end
        scoped
    end

Last edited by joelgrannas (2013-05-14 13:24:57)