method
not
v6.0.0 -
Show latest stable
- Class:
ActiveRecord::QueryMethods::WhereChain
not(opts, *rest)public
Returns a new relation expressing WHERE + NOT condition according to the conditions in the arguments.
#not accepts conditions as a string, array, or hash. See QueryMethods#where for more details on each format.
User.where.not("name = 'Jon'") # SELECT * FROM users WHERE NOT (name = 'Jon') User.where.not(["name = ?", "Jon"]) # SELECT * FROM users WHERE NOT (name = 'Jon') User.where.not(name: "Jon") # SELECT * FROM users WHERE name != 'Jon' User.where.not(name: nil) # SELECT * FROM users WHERE name IS NOT NULL User.where.not(name: %w(Ko1 Nobu)) # SELECT * FROM users WHERE name NOT IN ('Ko1', 'Nobu')