Class: ActiveRecord::Associations::AssociationScope
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::AssociationScope
- Includes:
- JoinHelper
- Defined in:
- lib/active_record/associations/association_scope.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#alias_tracker ⇒ Object
readonly
Returns the value of attribute alias_tracker.
-
#association ⇒ Object
readonly
Returns the value of attribute association.
Instance Method Summary collapse
-
#initialize(association) ⇒ AssociationScope
constructor
A new instance of AssociationScope.
- #scope ⇒ Object
Methods included from JoinHelper
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 klass.connection end |
Instance Attribute Details
#alias_tracker ⇒ Object (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 |
#association ⇒ Object (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
#scope ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_record/associations/association_scope.rb', line 16 def scope scope = klass.unscoped scope = scope.extending(*Array.wrap([: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.(.slice( :readonly, :include, :order, :limit, :joins, :group, :having, :offset, :select)) if [:through] && ![:include] scope = scope.includes([:include]) end scope = scope.uniq if [:uniq] add_constraints(scope) end |