【问题标题】:Rails 4.1.0 elasticsearch Tire associationRails 4.1.0 elasticsearch 轮胎关联
【发布时间】:2014-04-09 12:20:02
【问题描述】:

升级到 Rails 4.1.0 后,我的 (re)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)

我的问题是如何使用轮胎宝石加载相关模型? load:{:include => [:user, :tags] 正确吗?

提前感谢 JD。

【问题讨论】:

    标签: ruby-on-rails activerecord ruby-on-rails-4 associations tire


    【解决方案1】:

    轮胎使用klass.find(ids, @options[:load]) 执行负载。此发现行为已被弃用一段时间,但通过 gem activerecord-deprecated_finders 支持。 Rails 4.1.0 移除了对该 gem 的默认依赖。

    您应该能够自己将 gem 包含在 Gemfile 中以恢复行为:

    gem 'activerecord-deprecated_finders'
    

    【讨论】:

    • 不使用 gem 'activerecord-deprecated_finders'
    • 完全一样?在bundle install之后?
    猜你喜欢
    • 2013-07-21
    • 2013-09-26
    • 2013-07-23
    • 2012-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    相关资源
    最近更新 更多