Skip to content

MetaSearch struggle

by nick on June 3rd, 2011

TL;DR – MetaSearch doesn’t respond like you think it should when you try to use (named) scopes without registering with :search_methods first.

I ran across a strange issue with MetaSearch with a model I have:

class Order < ActiveRecord::Base
  scope :completed, {:conditions => "status='complete'"}
end

I was trying to do the following:

Order.search(:date_gte => Date.today - 14, :date_lt => Date.today + 1, :completed => true).

The resulting query looked like:

SELECT * FROM orders WHERE date < '2011-06-04'

My first thought was "MetaSearch does not support using multiple predicates per column. That's odd..." - but really it was that MetaSearch didn't completely finish creating all the wheres due to the use of the scope 'completed'. The fix was simply to call search_methods :completed. MetaSearch works as expected at that point.

It is important to say this is not an error with MetaSearch.

This gist should help too: https://gist.github.com/dbab58161d9a65cf5f1c. Add to config/initializers.

Related Posts

  • No Related Post

From → Geek

Comments are closed.