如何解决'从您的Finder中删除:: include => [:公司]'

时间:2017-07-16 04:30:53

标签: ruby-on-rails ruby-on-rails-4

当我尝试编写嵌套关系时,我收到了警告,无法获取公司数据。

  

检测到未使用的Eager Loading     用户=> [:公司]     从您的finder中删除:: includes => [:公司]

我写了下面的代码。 当我查看sql。它似乎与用户和公司建立联系。 但是这个控制器结果无法得到公司数据。 你知道如何解决这个问题吗?

控制器/ product.rb

def products
  Product
    .sale_date_between(params[:from], params[:to])
    .organization(current_user.company_id)
    .order('sale_date DESC')
end

模型/ product.rb

belongs_to :user
scope :with_user, -> { includes(:user, {user: :company}) }
scope :sale_date_between, ->(from, to) { where('sale_date_date >= ?', from).where('sale_date_date <= ?', to) }
scope :company, ->(id) { with_user.where(users: { company_id: id }) }

模型/ user.rb

has_many :products

模型/ company.rb

belongs_to :user, foreign_key: 'company_id'

0 个答案:

没有答案
相关问题