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.



1021
1022
1023
1024
# File 'lib/active_record/reflection.rb', line 1021

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

Instance Method Details

#constraintsObject



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

def constraints
  @reflection.constraints + [source_type_info]
end

#get_join_keys(association_klass) ⇒ Object



1074
1075
1076
# File 'lib/active_record/reflection.rb', line 1074

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

#join_scopes(table, predicate_builder) ⇒ Object

:nodoc:



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

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



1044
1045
1046
# File 'lib/active_record/reflection.rb', line 1044

def klass
  @reflection.klass
end

#plural_nameObject



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

def plural_name
  @reflection.plural_name
end

#scopeObject



1048
1049
1050
# File 'lib/active_record/reflection.rb', line 1048

def scope
  @reflection.scope
end

#scopesObject



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

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



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

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



1052
1053
1054
# File 'lib/active_record/reflection.rb', line 1052

def table_name
  @reflection.table_name
end

#typeObject



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

def type
  @reflection.type
end