ActiveRecord WHERE NOT EXISTS

Posted by jspooner on Stack Overflow See other posts from Stack Overflow or by jspooner
Published on 2010-05-25T22:58:48Z Indexed on 2010/05/25 23:01 UTC
Read the original article Hit count: 267

Filed under:

Is there a way to use EXISTS with ActiveRecord besides find_by_sql?

I'd like a nice way to find all records without an association in a One-to-Many relationship.

SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS (SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type)

© Stack Overflow or respective owner

Related posts about activerecord