not

not(opts, *rest)
Instance Public methods

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 where for more details on each format.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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')
 
User.where.not(name: "Jon", role: "admin")
# SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.