Class: ActiveRecord::Associations::AssociationScope
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::AssociationScope
- Defined in:
- lib/active_record/associations/association_scope.rb
Overview
:nodoc:
Defined Under Namespace
Classes: ReflectionProxy
Constant Summary collapse
- INSTANCE =
create
Class Method Summary collapse
- .create(&block) ⇒ Object
- .get_bind_values(owner, chain) ⇒ Object
- .scope(association, connection) ⇒ Object
Instance Method Summary collapse
-
#initialize(value_transformation) ⇒ AssociationScope
constructor
A new instance of AssociationScope.
- #join_type ⇒ Object
- #scope(association, connection) ⇒ Object
Constructor Details
#initialize(value_transformation) ⇒ AssociationScope
Returns a new instance of AssociationScope.
13 14 15 |
# File 'lib/active_record/associations/association_scope.rb', line 13 def initialize(value_transformation) @value_transformation = value_transformation end |
Class Method Details
.create(&block) ⇒ Object
8 9 10 11 |
# File 'lib/active_record/associations/association_scope.rb', line 8 def self.create(&block) block ||= lambda { |val| val } new(block) end |
.get_bind_values(owner, chain) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/active_record/associations/association_scope.rb', line 35 def self.get_bind_values(owner, chain) binds = [] last_reflection = chain.last binds << last_reflection.join_id_for(owner) if last_reflection.type binds << owner.class.base_class.name end chain.each_cons(2).each do |reflection, next_reflection| if reflection.type binds << next_reflection.klass.base_class.name end end binds end |
.scope(association, connection) ⇒ Object
4 5 6 |
# File 'lib/active_record/associations/association_scope.rb', line 4 def self.scope(association, connection) INSTANCE.scope(association, connection) end |
Instance Method Details
#join_type ⇒ Object
31 32 33 |
# File 'lib/active_record/associations/association_scope.rb', line 31 def join_type Arel::Nodes::InnerJoin end |
#scope(association, connection) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_record/associations/association_scope.rb', line 19 def scope(association, connection) klass = association.klass reflection = association.reflection scope = klass.unscoped owner = association.owner alias_tracker = AliasTracker.create connection, association.klass.table_name, klass.type_caster chain_head, chain_tail = get_chain(reflection, association, alias_tracker) scope.extending! Array(reflection.[:extend]) add_constraints(scope, owner, reflection, chain_head, chain_tail) end |