Skip to content

Instantly share code, notes, and snippets.

@michaelminter
Created October 18, 2012 02:35
Show Gist options
  • Select an option

  • Save michaelminter/3909556 to your computer and use it in GitHub Desktop.

Select an option

Save michaelminter/3909556 to your computer and use it in GitHub Desktop.
Find an array of objects by whats NOT available
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] }}
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);
@michaelminter
Copy link
Copy Markdown
Author

3, is the variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment