123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::Reflection::PolymorphicReflection

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActiveRecord::Reflection::AbstractReflection
Defined in: activerecord/lib/active_record/reflection.rb

Class Method Summary

Instance Attribute Summary

AbstractReflection - Inherited

#counter_must_be_updated_by_has_many?,
#has_active_cached_counter?

Returns whether this association has a counter cache and its column values were backfilled (and so it is used internally by methods like size/+any?+/etc).

#has_cached_counter?

Returns whether this association has a counter cache.

#inverse_updates_counter_cache?
#inverse_updates_counter_in_memory?, #strict_loading?, #through_reflection?

Instance Method Summary

AbstractReflection - Inherited

#alias_candidate,
#build_association

Returns a new, unsaved instance of the associated class.

#build_scope, #chain, #check_validity_of_inverse!,
#class_name

Returns the class name for the macro.

#constraints, #counter_cache_column, #inverse_of,
#inverse_which_updates_counter_cache

We need to avoid the following situation:

#join_scope, #join_scopes, #klass_join_scope,
#scopes

Returns a list of scopes that should be applied for this ::ActiveRecord::Reflection object when querying the database.

#strict_loading_violation_message, #table_name,
#actual_source_reflection

FIXME: this is a horrible name.

#ensure_option_not_given_as_class!,
#inferred_primary_key_definition

The Key form of a model's inferred primary key.

#primary_key, #primary_key_definition

Constructor Details

.new(reflection, previous_reflection) ⇒ PolymorphicReflection

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 1364

def initialize(reflection, previous_reflection)
  super()
  @reflection = reflection
  @previous_reflection = previous_reflection
end

Instance Attribute Details

#join_foreign_key (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 1361

delegate :klass, :scope, :plural_name, :type, :join_primary_key, :join_primary_key_definition,
         :join_foreign_key, :join_foreign_key_definition, :name, :scope_for, to: :@reflection

#join_foreign_key_definition (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 1361

delegate :klass, :scope, :plural_name, :type, :join_primary_key, :join_primary_key_definition,
         :join_foreign_key, :join_foreign_key_definition, :name, :scope_for, to: :@reflection

#join_primary_key (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 1361

delegate :klass, :scope, :plural_name, :type, :join_primary_key, :join_primary_key_definition,
         :join_foreign_key, :join_foreign_key_definition, :name, :scope_for, to: :@reflection

#join_primary_key_definition (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 1361

delegate :klass, :scope, :plural_name, :type, :join_primary_key, :join_primary_key_definition,
         :join_foreign_key, :join_foreign_key_definition, :name, :scope_for, to: :@reflection

#klass (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 1361

delegate :klass, :scope, :plural_name, :type, :join_primary_key, :join_primary_key_definition,
         :join_foreign_key, :join_foreign_key_definition, :name, :scope_for, to: :@reflection

#name (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 1361

delegate :klass, :scope, :plural_name, :type, :join_primary_key, :join_primary_key_definition,
         :join_foreign_key, :join_foreign_key_definition, :name, :scope_for, to: :@reflection

#plural_name (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 1361

delegate :klass, :scope, :plural_name, :type, :join_primary_key, :join_primary_key_definition,
         :join_foreign_key, :join_foreign_key_definition, :name, :scope_for, to: :@reflection

#scope (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 1361

delegate :klass, :scope, :plural_name, :type, :join_primary_key, :join_primary_key_definition,
         :join_foreign_key, :join_foreign_key_definition, :name, :scope_for, to: :@reflection

#scope_for (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 1361

delegate :klass, :scope, :plural_name, :type, :join_primary_key, :join_primary_key_definition,
         :join_foreign_key, :join_foreign_key_definition, :name, :scope_for, to: :@reflection

#type (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 1361

delegate :klass, :scope, :plural_name, :type, :join_primary_key, :join_primary_key_definition,
         :join_foreign_key, :join_foreign_key_definition, :name, :scope_for, to: :@reflection

Instance Method Details

#constraints

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 1378

def constraints
  @reflection.constraints + [source_type_scope]
end

#join_scopes(table, predicate_builder = nil, klass = self.klass, record = nil)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 1370

def join_scopes(table, predicate_builder = nil, klass = self.klass, record = nil) # :nodoc:
  scopes = super
  unless @previous_reflection.through_reflection?
    scopes += @previous_reflection.join_scopes(table, predicate_builder, klass, record)
  end
  scopes << build_scope(table, predicate_builder, klass).instance_exec(record, &source_type_scope)
end

#source_type_scope (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/reflection.rb', line 1383

def source_type_scope
  type = @previous_reflection.foreign_type
  source_type = @previous_reflection.options[:source_type]
  lambda { |object| where(type => source_type) }
end