Problem with Thinking Sphinx and scopes
For several hours now I am unsuccessfully trying to get sphinx scopes work.
I want to scope tags of ActsAsTaggableOn. In my model (that is taggable) I tried the following scopes:
# This normal scope works
scope :tagged, lambda {
joins(:taggings => :tag).
where("tags.name = 'consequatur'")
}
# fails! (can't convert ActiveRecord::Relation into Hash)
sphinx_scope :tagged do
joins(:taggings => :tag).
where("tags.name = 'consequatur'")
end
Another try with the old conditions:
# works with normal scope (returns one record)
scope :tagged, :joins => :taggings, :conditions => {"taggings.tag_id" => 74}
# fails! (returns nothing)
sphinx_s开发者_StackOverflow中文版cope(:tagged) do
{:joins => :taggings, :conditions => {"taggings.tag_id" => 74}}
end
How can I make those scopes work? Is there another way to archive that task? I want to only search those models that are tagged with a specific tag.
精彩评论