Created
October 18, 2012 02:35
-
-
Save michaelminter/3909556 to your computer and use it in GitHub Desktop.
Find an array of objects by whats NOT available
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| scope :not_in_user_locations, lambda { |user| { :conditions => ['locations.id NOT IN (SELECT locations.id FROM locations JOIN user_locations ON user_locations.location_id = locations.id WHERE user_locations.user_id = ?)', user.id] }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT * FROM locations | |
| WHERE locations.id NOT IN ( | |
| SELECT locations.id FROM locations | |
| JOIN user_locations ON user_locations.location_id = locations.id | |
| WHERE user_locations.user_id = 3); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
3, is the variable