Class: ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation

Inherits:
JoinPart
  • Object
show all
Defined in:
activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb

Overview

:nodoc:

Instance Attribute Summary (collapse)

Attributes inherited from JoinPart

#active_record

Instance Method Summary (collapse)

Methods inherited from JoinPart

#aliased_primary_key, #aliased_table, #column_names_with_alias, #extract_record, #instantiate, #record_id

Constructor Details

- (JoinAssociation) initialize(reflection, join_dependency, parent = nil)

A new instance of JoinAssociation



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb', line 27

def initialize(reflection, join_dependency, parent = nil)
  reflection.check_validity!

  if reflection.options[:polymorphic]
    raise EagerLoadPolymorphicError.new(reflection)
  end

  super(reflection.klass)

  @reflection      = reflection
  @join_dependency = join_dependency
  @parent          = parent
  @join_type       = Arel::InnerJoin
  @aliased_prefix  = "t#{ join_dependency.join_parts.size }"

  # This must be done eagerly upon initialisation because the alias which is produced
  # depends on the state of the join dependency, but we want it to work the same way
  # every time.
  allocate_aliases
  @table = Arel::Table.new(
    table_name, :as => aliased_table_name, :engine => arel_engine
  )
end

Instance Attribute Details

- (Object) aliased_prefix (readonly)

These implement abstract methods from the superclass



22
23
24
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb', line 22

def aliased_prefix
  @aliased_prefix
end

- (Object) aliased_table_name (readonly)

These implement abstract methods from the superclass



22
23
24
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb', line 22

def aliased_table_name
  @aliased_table_name
end

- (Object) join_dependency (readonly)

The JoinDependency object which this JoinAssociation exists within. This is mainly relevant for generating aliases which do not conflict with other joins which are part of the query.



12
13
14
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb', line 12

def join_dependency
  @join_dependency
end

- (Object) join_type

What type of join will be generated, either Arel::InnerJoin (default) or Arel::OuterJoin



19
20
21
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb', line 19

def join_type
  @join_type
end

- (Object) parent (readonly)

A JoinBase instance representing the active record we are joining onto. (So in Author.has_many :posts, the Author would be that base record.)



16
17
18
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb', line 16

def parent
  @parent
end

- (Object) reflection (readonly)

The reflection of the association represented



7
8
9
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb', line 7

def reflection
  @reflection
end

- (Object) table (readonly) Also known as: target_table

Returns the value of attribute table



72
73
74
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb', line 72

def table
  @table
end

Instance Method Details

- (Object) ==(other)



51
52
53
54
55
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb', line 51

def ==(other)
  other.class == self.class &&
    other.reflection == reflection &&
    other.parent == parent
end

- (Object) find_parent_in(other_join_dependency)



57
58
59
60
61
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb', line 57

def find_parent_in(other_join_dependency)
  other_join_dependency.join_parts.detect do |join_part|
    parent == join_part
  end
end

- (Object) join_relation(joining_relation)



67
68
69
70
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb', line 67

def join_relation(joining_relation)
  self.join_type = Arel::OuterJoin
  joining_relation.joins(self)
end

- (Object) join_to(relation)



63
64
65
# File 'activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb', line 63

def join_to(relation)
  send("join_#{reflection.macro}_to", relation)
end