Class: ActiveRecord::Reflection::PolymorphicReflection

Inherits:
AbstractReflection show all
Defined in:
lib/active_record/reflection.rb

Overview

:nodoc:

Direct Known Subclasses

RuntimeReflection

Instance Method Summary collapse

Methods inherited from AbstractReflection

#alias_candidate, #build_association, #chain, #check_validity_of_inverse!, #class_name, #counter_cache_column, #counter_must_be_updated_by_has_many?, #has_cached_counter?, #inverse_of, #inverse_updates_counter_in_memory?, #inverse_which_updates_counter_cache, #join_keys, #klass_join_scope, #primary_key_type, #quoted_table_name, #scope_chain, #through_reflection?

Constructor Details

#initialize(reflection, previous_reflection) ⇒ PolymorphicReflection

Returns a new instance of PolymorphicReflection.



1019
1020
1021
1022
# File 'lib/active_record/reflection.rb', line 1019

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

Instance Method Details

#constraintsObject



1062
1063
1064
# File 'lib/active_record/reflection.rb', line 1062

def constraints
  @reflection.constraints + [source_type_info]
end

#get_join_keys(association_klass) ⇒ Object



1072
1073
1074
# File 'lib/active_record/reflection.rb', line 1072

def get_join_keys(association_klass)
  @reflection.get_join_keys(association_klass)
end

#join_scopes(table, predicate_builder) ⇒ Object

:nodoc:



1033
1034
1035
1036
1037
1038
1039
1040
# File 'lib/active_record/reflection.rb', line 1033

def join_scopes(table, predicate_builder) # :nodoc:
  scopes = @previous_reflection.join_scopes(table, predicate_builder) + super
  if @previous_reflection.options[:source_type]
    scopes + [@previous_reflection.source_type_scope]
  else
    scopes
  end
end

#klassObject



1042
1043
1044
# File 'lib/active_record/reflection.rb', line 1042

def klass
  @reflection.klass
end

#plural_nameObject



1054
1055
1056
# File 'lib/active_record/reflection.rb', line 1054

def plural_name
  @reflection.plural_name
end

#scopeObject



1046
1047
1048
# File 'lib/active_record/reflection.rb', line 1046

def scope
  @reflection.scope
end

#scopesObject



1024
1025
1026
1027
1028
1029
1030
1031
# File 'lib/active_record/reflection.rb', line 1024

def scopes
  scopes = @previous_reflection.scopes
  if @previous_reflection.options[:source_type]
    scopes + [@previous_reflection.source_type_scope]
  else
    scopes
  end
end

#source_type_infoObject



1066
1067
1068
1069
1070
# File 'lib/active_record/reflection.rb', line 1066

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

#table_nameObject



1050
1051
1052
# File 'lib/active_record/reflection.rb', line 1050

def table_name
  @reflection.table_name
end

#typeObject



1058
1059
1060
# File 'lib/active_record/reflection.rb', line 1058

def type
  @reflection.type
end