Hello all,
I just started using Sphinx for full text search. It works very well, but I can't figure out how to set a condition for a has_many relationship.
For example, I have a Game model, and it has a habtm relationship with Category. I want to search all games, but filter all results by a particular category. Without sphinx, you would do this by
Game.all :conditions => { "categories_games.category_id" => 1 }, :include => :categories
This works fine, but when I try to do this, it doesn't work
Game.search params[:q], :conditions => { "categories_games.category_id" => 1 }, :include => :categories
This is understandable, because for conditions to work with sphinx, they have to be indexed. If I add the following to the index
has players
I can do this
Game.search params[:q], :conditions => { :players => 2 }
Apparently, the way to index a habtm relationship is
has categories(:id), :as => :category_ids
But I have no idea how to add it to the search. The conditions thing I mentioned above doesn't work, neither does setting :category_ids => 1 in my conditions.
How can I do this? Thanks! ~sean
Example: http://pastie.textmate.org/247713