Rails 5.1.2 ransack包括如何添加深层关联?

时间:2017-08-02 10:45:01

标签: ruby-on-rails ruby-on-rails-5

我有以下模型,我希望搜索订单模型,其中包含与模型部门供应商相关的标准

问题是如何在此代码中包含其他模型供应商和部门

@q = Order.ransack(params[:q])
@objednavky = @q.result.includes(:user,:food).page(params[:page])

模型的定义

class Supplier < ApplicationRecord
  has_many :food
end

class User < ApplicationRecord
  belongs_to :department
  has_many :orders
end

class Department < ApplicationRecord
  has_many :users
end

class Food < ApplicationRecord
  belongs_to :supplier
  has_many :order 
end

class Order < ApplicationRecord
  belongs_to :user
  belongs_to :food
end

0 个答案:

没有答案