The problem with the thinking of the Sphinx and areas

For several hours I have been unsuccessfully trying to use the areas of the sphinxes.

I want to use ActsAsTaggableOn scope tags. In my model (i.e. taggable), I tried the following areas:

# 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 old conditions:

# works with normal scope (returns one record)
scope :tagged, :joins => :taggings, :conditions => {"taggings.tag_id" => 74}

# fails! (returns nothing)
sphinx_scope(:tagged) do
  {:joins => :taggings, :conditions => {"taggings.tag_id" => 74}}
end

How can I make these areas work? Is there any other way to archive this task? I only want to search for models that are tagged with a specific tag.

+3
source share

Source: https://habr.com/ru/post/1776738/


All Articles