我有这段代码:
def self.table_with_finished_or_no_orders
Table.joins("left join orders
on orders.table_id=tables.id")
.where("orders.finished = ? OR orders.table_id is NULL", true)
end
但我想只选择DISTINCT
个表格。我该如何修改?
修改
生成的SQL:
SELECT `tables`.* FROM `tables`
left join orders on orders.table_id=tables.id
WHERE (orders.finished = 1 OR orders.table_id is NULL)