Rails, ActiveRecord, how to find foreign rows that are NOT there?
Posted
by randombits
on Stack Overflow
See other posts from Stack Overflow
or by randombits
Published on 2010-05-28T20:38:30Z
Indexed on
2010/05/28
20:42 UTC
Read the original article
Hit count: 141
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);
© Stack Overflow or respective owner