Quick Explanation of SUBQUERY in NSPredicate Expression

And for people who don’t quite get what the documentation is saying, a SUBQUERY is essentially this: SUBQUERY(collection, variableName, predicateFormat) And could (simplistically) be implemented like this: id resultingCollection = …; //a new collection, either a mutable set or array NSMutableDictionary * substitutions = [NSMutableDictionary dictionary]; NSPredicate * p = [NSPredicate predicateWithFormat:predicateFormat]; for (id variable … Read more

Subqueries in activerecord

Rails now does this by default 🙂 Message.where(user_id: Profile.select(“user_id”).where(gender: ‘m’)) will produce the following SQL SELECT “messages”.* FROM “messages” WHERE “messages”.”user_id” IN (SELECT user_id FROM “profiles” WHERE “profiles”.”gender” = ‘m’) (the version number that “now” refers to is most likely 3.2)