How would I use active record in this case:
I have two tables: Users, Admins
Admins can be users also and thus have a user_id in their table.
I’d like to Select all users that DO NOT have a user_id set in the admins table
NOTE: This is just an example case. If this was a real case then of course I wouldn’t have two different tables for users and admins.
Edit: Again, I know the semantics of doing it like this is terrible db design — but it’s just an dummy case.
You can use
:conditionsto include aNOT IN:OR you can code it into a User’s
scope( a.k.a.named_scopeprior to Rails 3.x ):And use it as:
OR in order not to depend on
@adminsvariable being passed you can usejoins: