How do you do a query that includes a "where exists" in Arel? For example on a query like this to show all the suppliers with at least one order:
SELECT *
FROM suppliers
WHERE EXISTS
(SELECT *
FROM orders
WHERE suppliers.supplier_id = orders.supplier_id);
I see "exists" in the Arel docs http://rubydoc.info/gems/arel/2.0.7/Arel/Nodes/Exists but I'm having trouble using it.
I think that you can neatly use a counter_cache for this one :
http://asciicasts.com/episodes/23-counter-cache-column
Here you go:
Though, an inner join would do this in a more simple - and eventually less performant - way :