Skip to content

Instantly share code, notes, and snippets.

@mkhuda
Created June 3, 2017 01:29
Show Gist options
  • Save mkhuda/36d521285ba45c7f66e692ecc553c9bf to your computer and use it in GitHub Desktop.
Save mkhuda/36d521285ba45c7f66e692ecc553c9bf to your computer and use it in GitHub Desktop.
Using INCLUDES and WHERE NOT IN on ActiveRecord
# select user where id not in and where translator category is
def search
User.includes(:levels, :translator_categories).where('levels.name = ? AND translator_categories.name = ?', 'translator', 'Umum').where('users.id NOT IN (?)', [1,5,3,2]).references(:levels, :translator_categories)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment