mirror of https://github.com/rails/rails
Merge pull request #41465 from ashiksp/active_record_query_without
Added ActiveRecord::Relation#without as alias for #excluding.
This commit is contained in:
commit
5b988afda4
|
@ -17,7 +17,7 @@ module ActiveRecord
|
|||
:and, :or, :annotate, :optimizer_hints, :extending,
|
||||
:having, :create_with, :distinct, :references, :none, :unscope, :merge, :except, :only,
|
||||
:count, :average, :minimum, :maximum, :sum, :calculate,
|
||||
:pluck, :pick, :ids, :strict_loading, :excluding
|
||||
:pluck, :pick, :ids, :strict_loading, :excluding, :without
|
||||
].freeze # :nodoc:
|
||||
delegate(*QUERYING_METHODS, to: :all)
|
||||
|
||||
|
|
|
@ -1140,6 +1140,11 @@ module ActiveRecord
|
|||
spawn.excluding!(records)
|
||||
end
|
||||
|
||||
# Alias for #excluding.
|
||||
def without(*records)
|
||||
excluding(*records)
|
||||
end
|
||||
|
||||
def excluding!(records) # :nodoc:
|
||||
# Treat single and multiple records differently in order to keep query
|
||||
# clean in case of single record, ie, use != operator instead of NOT IN ().
|
||||
|
|
|
@ -68,4 +68,10 @@ class ExcludingTest < ActiveRecord::TestCase
|
|||
end
|
||||
assert_equal "You must only pass a single or collection of Post objects to #excluding.", exception.message
|
||||
end
|
||||
|
||||
def test_result_set_does_not_include_without_record
|
||||
post = posts(:welcome)
|
||||
|
||||
assert_not_includes Post.without(post).to_a, post
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue