Skip to content

Commit

Permalink
Merge pull request rails#50367 from mechanicles/update-api-doc-for-ac…
Browse files Browse the repository at this point in the history
…tiverelation-none-any-one

Update API doc for ActiveRecord::Relation#none?/#any?/#one? [ci-skip]
  • Loading branch information
p8 authored Dec 18, 2023
2 parents 2ec0ff4 + 45ce025 commit 462e8e8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions activerecord/lib/active_record/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ def empty?
end

# Returns true if there are no records.
#
# When a pattern argument is given, this method checks whether elements in
# the Enumerable match the pattern via the case-equality operator (`===`).
#
# posts.none?(Comment) # => true or false
def none?(*args)
return true if @none

Expand All @@ -299,6 +304,11 @@ def none?(*args)
end

# Returns true if there are any records.
#
# When a pattern argument is given, this method checks whether elements in
# the Enumerable match the pattern via the case-equality operator (`===`).
#
# posts.any?(Post) # => true or false
def any?(*args)
return false if @none

Expand All @@ -307,6 +317,11 @@ def any?(*args)
end

# Returns true if there is exactly one record.
#
# When a pattern argument is given, this method checks whether elements in
# the Enumerable match the pattern via the case-equality operator (`===`).
#
# posts.one?(Post) # => true or false
def one?(*args)
return false if @none

Expand Down

0 comments on commit 462e8e8

Please sign in to comment.