0
class Project
has_many :quotes
scope :available, ->(business_id) { joins(:quotes).where.not(quotes: { business_id: business_id }) }
scope :active, ->(business_id) { joins(:quotes).where(quotes: { business_id: business_id }) }
end
class Quote
belongs_to :project
end
嗨,我试图定义一个available
范围返回的Project
记录的关系不具有对给定business_id
一个Quote
。我试过使用上面的范围,但它返回一个空关系?查找记录,其中记录的关联属性都不是一个定值
类似的active
范围似乎工作正常。这里唯一的区别是.not()
条款。
任何想法?我必须为此编写原始SQL吗?
http://stackoverflow.com/a/31256399/2697183 – AbM
@AbM这并不是问题 –