【发布时间】:2015-01-29 10:35:30
【问题描述】:
我需要创建一个查询,该查询将根据会议返回所有买家
我有 2 个模型
class Buyer < ActiveRecord::Base
has_many :meetings
end
class Meeting < ActiveRecord::Base
belongs_to :buyer
end
Buyers(id, name)
Meetings(id, buyer_id, value)
现在我需要创建一个查询,它将返回所有没有会面的买家,值为 false
我的意思是从这些记录中:
Buyers:
1, Toms
2, Ingus
Meetings
1, 1, true
2, 1, false
3, 2, true
4, 2, true
应该只选择 Ingus
编辑:
我猜查询看起来像这样
select * from Buyers where id in (select buyer_id from Meetings where value = false group by buyer_id having count(*) = 0)
但是如何在 Rails 中如此漂亮?
【问题讨论】:
标签: sql ruby-on-rails join