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?.
# File activerecord/lib/active_record/relation/finder_methods.rb, line 389
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?(model)
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