I have a collection of ActiveRecord models queried from the database. I would like to perform a Tire search on that Relation object returned from ActiveRecord, e.g:
class Model_1
has_many :model_2
end
class Model_2
attr_accessible :attr_1, :attr_2, :attr_3
belongs_to :model_1
end
class Model2Controller
def index
@model_2s = @model_1.model_2s
# How can I query single or multiple fields here?
@model_2s.search :query => { :attr_1 => params[:q] }
end
end
I would like to query that ActiveRecord:Relation using a single or multiple fields. Which fields I would like to query (:attr_1
or :attr_2
or :attr_3
), is dynamic, so it would be nice if I could send a Hash
to the query method.
Is something like this possible?
Not 100% sure what you are asking, but if it is "I want to find the model_2s that have parameters x, y and z equals to something specific", then you can use the Ruby Array #Select
If this is not what your are asking, please rewrite your question a bit.