Rails:查找has_one关系的记录

时间:2014-01-15 21:43:02

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

我的用户模型有很多设计,而且还有很多design_request通过设计

现在我的design_request模型has_one命令。如何通过订单状态==“付费”为用户获取所有设计请求

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

2 个答案:

答案 0 :(得分:1)

你尝试过类似的事情吗?

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

答案 1 :(得分:0)

这有用吗? user.design_requests.select {| dr | dr.order.state ==“付费”}