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這並不是問題 –