| Class | Criteria::Join |
| In: |
lib/join.rb
|
| Parent: | TableAlias |
| parent | [R] | |
| reflection | [R] | |
| table_alias | [RW] |
# File lib/join.rb, line 14
14: def initialize(attribute, parent)
15: @reflection = attribute
16: @query = parent.query
17: @parent = parent
18: association_reflection = parent.model_class.reflect_on_association(attribute.intern)
19:
20: # if we cannot reflect on the attribute, raise an exception
21: raise "#{attribute} is not a relationship on class #{parent.model_class}" unless association_reflection
22:
23: # if this is a polymorphic has_one or has_many association, raise an error as AR cannot support that
24: raise "Eager loading for the has_one or has_many side of a polymorphic association cannot be supported by ActiveRecord" if association_reflection.options.include? :polymorphic
25:
26: @model_class = association_reflection.klass
27:
28: # build the alias for this join - need to take into account all other joins that
29: # have been defined for the query because of the AR aliasing scheme
30: @alias = @query.join_alias(self)
31: end