Class: ActiveRecord::Associations::AssociationScope

Inherits:
Object
  • Object
show all
Includes:
JoinHelper
Defined in:
lib/active_record/associations/association_scope.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JoinHelper

#join_type

Constructor Details

#initialize(association) ⇒ AssociationScope

Returns a new instance of AssociationScope.



11
12
13
14
# File 'lib/active_record/associations/association_scope.rb', line 11

def initialize(association)
  @association   = association
  @alias_tracker = AliasTracker.new
end

Instance Attribute Details

#alias_trackerObject (readonly)

Returns the value of attribute alias_tracker.



6
7
8
# File 'lib/active_record/associations/association_scope.rb', line 6

def alias_tracker
  @alias_tracker
end

#associationObject (readonly)

Returns the value of attribute association.



6
7
8
# File 'lib/active_record/associations/association_scope.rb', line 6

def association
  @association
end

Instance Method Details

#scopeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_record/associations/association_scope.rb', line 16

def scope
  scope = klass.unscoped
  scope = scope.extending(*Array.wrap(options[:extend]))

  # It's okay to just apply all these like this. The options will only be present if the
  # association supports that option; this is enforced by the association builder.
  scope = scope.apply_finder_options(options.slice(
    :readonly, :include, :order, :limit, :joins, :group, :having, :offset))

  if options[:through] && !options[:include]
    scope = scope.includes(source_options[:include])
  end

  if select = select_value
    scope = scope.select(select)
  end

  add_constraints(scope)
end