Rails, ActiveRecord, how to find foreign rows that are NOT there?
- by randombits
The title is a bit difficult to put together for this question.
Say I have two models, Foo and Bar. Foo has many Bar's. Bar belongs to one Foo. How do I use Foo.find to find all of the Foos that currently have zero Bars? In SQL this would translate into something like:
SELECT * from foo where id NOT IN (select foo_id from bar);