开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜