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, #build_scope, #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, #join_scope, #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.



1033
1034
1035
1036
# File 'lib/active_record/reflection.rb', line 1033

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

Instance Method Details

#constraintsObject



1076
1077
1078
# File 'lib/active_record/reflection.rb', line 1076

def constraints
  @reflection.constraints + [source_type_info]
end

#get_join_keys(association_klass) ⇒ Object



1086
1087
1088
# File 'lib/active_record/reflection.rb', line 1086

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

#join_scopes(table, predicate_builder) ⇒ Object

:nodoc:



1047
1048
1049
1050
1051
1052
1053
1054
# File 'lib/active_record/reflection.rb', line 1047

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



1056
1057
1058
# File 'lib/active_record/reflection.rb', line 1056

def klass
  @reflection.klass
end

#plural_nameObject



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

def plural_name
  @reflection.plural_name
end

#scopeObject



1060
1061
1062
# File 'lib/active_record/reflection.rb', line 1060

def scope
  @reflection.scope
end

#scopesObject



1038
1039
1040
1041
1042
1043
1044
1045
# File 'lib/active_record/reflection.rb', line 1038

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



1080
1081
1082
1083
1084
# File 'lib/active_record/reflection.rb', line 1080

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



1064
1065
1066
# File 'lib/active_record/reflection.rb', line 1064

def table_name
  @reflection.table_name
end

#typeObject



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

def type
  @reflection.type
end