instance method include?

Ruby on Rails 6.1.7.10

Since v6.1.7.10

Available in: v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

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

record req
Source
# File activerecord/lib/active_record/relation/finder_methods.rb, line 328
    def include?(record)
      if loaded? || offset_value || limit_value || having_clause.any?
        records.include?(record)
      else
        record.is_a?(klass) && exists?(record.id)
      end
    end

Defined in activerecord/lib/active_record/relation/finder_methods.rb line 328 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::FinderMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close