简体   繁体   中英

Rails 4.1.0 elasticsearch Tire association

I'm getting an error with my (re)Tire gem integration after upgrading to Rails 4.1.0 Before i was running This code in my Product Model with Rails 4.0.4 :

def self.search(params)
  tire.search( load:{:include => [:user, :tags]}, match_all: {}, page: params[:page], per_page: 12) do
    sort do
        by :created_at, 'desc'
        end
    query do
      boolean do
        must { string params[:query], default_operator: "AND" } 
        must { term :online, true }
        must_not { string 'location:Undefined' }
      end
    end
  end
end

It was working fine, but now ActiveRecord throw me this error :

Couldn't find all Products with 'id': (1118, 1036, {:include=>[:user, :tags]}) (found 2 results, but was looking for 3)

My question is how can i do to load associated models with Tire gem? is load:{:include => [:user, :tags] correct?

Thanks in advance JD.

Tire performs the load using klass.find(ids, @options[:load]) . This find behavious has been deprecated for a while but supported via a gem activerecord-deprecated_finders . Rails 4.1.0 removed the default dependency on that gem.

You should be able to include the gem in your Gemfile yourself to restore the behaviour:

gem 'activerecord-deprecated_finders'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM