0

我有,有許多設計,還通過設計的Rails:查找記錄與HAS_ONE關係

現在我design_request模型HAS_ONE爲了HAS_MANY design_request用戶模型。我怎麼可以得到所有的設計要求與訂單狀態==「支付」的用戶

my user model is below 
    ##User Model 
    has_many :designs 
    has_many :design_requests, through: :designs 

    ##Design Model 
    has_many :design_requests 

##Design Request Model 
    belongs_to :design 
    belongs_to :user 
    validates :business_name, :design_id, presence: true 
    delegate :name, to: :design 
    has_one :order, as: :item 

回答

1

你嘗試過這樣的:

user.design_requests.includes(:order).where(orders: {state: "paid"}) 
0

工作的呢? user.design_requests.select {| dr | dr.order.state ==「paid」}