升级到Rails 4.1.0后,我的(重新)Tire gem集成出错了
在我使用Rails 4.0.4在我的Product Model
中运行此代码之前:
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
它工作正常,但现在ActiveRecord抛出了这个错误:
Couldn't find all Products with 'id': (1118, 1036, {:include=>[:user, :tags]}) (found 2 results, but was looking for 3)
我的问题是如何使用Tire gem加载相关模型?
load:{:include => [:user, :tags]
是否正确?
先谢谢JD。
答案 0 :(得分:0)
轮胎使用klass.find(ids, @options[:load])
执行加载。此查找行为已被弃用了一段时间,但通过gem activerecord-deprecated_finders支持。 Rails 4.1.0删除了该gem的默认依赖项。
您应该能够自己在Gemfile中包含gem以恢复行为:
gem 'activerecord-deprecated_finders'