instance method extract_associated

Ruby on Rails 7.2.3

Since v6.0.6

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

Signature

extract_associated(association)

Extracts a named association from the relation. The named association is first preloaded, then the individual association records are collected from the relation. Like so:

account.memberships.extract_associated(:user)
# => Returns collection of User records

This is short-hand for:

account.memberships.preload(:user).collect(&:user)

Parameters

association req
Source
# File activerecord/lib/active_record/relation/query_methods.rb, line 334
    def extract_associated(association)
      preload(association).collect(&association)
    end

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

Defined in ActiveRecord::QueryMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close