I have an array of team names from another part of code and I want to find all the Teams not in that array. I've tried the following and it doesn't work.
@team_exclude_list = ['Team 1', 'Team 2', 'Team 3']
@teams = Team.where("name != ?", @team_exclude_list)
This is in Rails 3 and the Googles aren't giving me much love.
Rails 4 solution:
@team_exclude_list = ['Team 1', 'Team 2', 'Team 3']
@teams = Team.where.not(name: @team_exclude_list)
Also, to speed up the query, you can:
OR
I've never done this with a string field, but perhaps this will work:
@teams = Team.where("name NOT IN (?)", @team_exclude_list)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With