广告系列包含属性:start_date,:end_date
发票包含属性:start_date,:end_date
campaign.rb
has_many:invoices
invoice.rb
belongs_to:campaign'
我想让所有没有发票并且end_date
小于当前日期的广告系列。
我试过这个
Campaign.includes(:invoices).where("compaigns.end_date > ? ",Date.today, :invoices => { :campaign_id => nil } ).count
我是怎么做到的?
答案 0 :(得分:2)
我想你差不多了。给出的示例不起作用,因为它混合了where
的字符串和散列形式。尝试将条件分为两个where
调用:
Campaign.includes(:invoices).
where("campaigns.end_date > ? ",Date.today).
where(invoices: {campaign_id: nil}).count