instance method
include?
Ruby on Rails 7.1.6
Since v6.1.7.10Signature
include?(record)
Returns true if the relation contains the given record or false otherwise.
No query is performed if the relation is loaded; the given record is compared to the records in memory. If the relation is unloaded, an efficient existence query is performed, as in #exists?.
Parameters
-
recordreq
Source
# File activerecord/lib/active_record/relation/finder_methods.rb, line 377
def include?(record)
# The existing implementation relies on receiving an Active Record instance as the input parameter named record.
# Any non-Active Record object passed to this implementation is guaranteed to return `false`.
return false unless record.is_a?(klass)
if loaded? || offset_value || limit_value || having_clause.any?
records.include?(record)
else
id = if record.class.composite_primary_key?
record.class.primary_key.zip(record.id).to_h
else
record.id
end
exists?(id)
end
end
Defined in activerecord/lib/active_record/relation/finder_methods.rb line 377
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::FinderMethods