Class: ActiveRecord::Reflection::AbstractReflection

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

Overview

Holds all the methods that are shared between MacroReflection, AssociationReflection and ThroughReflection

Direct Known Subclasses

MacroReflection, ThroughReflection

Defined Under Namespace

Classes: JoinKeys

Instance Method Summary collapse

Instance Method Details

#build_association(attributes, &block) ⇒ Object

Returns a new, unsaved instance of the associated class. attributes will be passed to the class’s constructor.



140
141
142
# File 'lib/active_record/reflection.rb', line 140

def build_association(attributes, &block)
  klass.new(attributes, &block)
end

#check_validity_of_inverse!Object



181
182
183
184
185
186
187
# File 'lib/active_record/reflection.rb', line 181

def check_validity_of_inverse!
  unless polymorphic?
    if has_inverse? && inverse_of.nil?
      raise InverseOfAssociationNotFoundError.new(self)
    end
  end
end

#class_nameObject

Returns the class name for the macro.

composed_of :balance, class_name: 'Money' returns 'Money' has_many :clients returns 'Client'



156
157
158
# File 'lib/active_record/reflection.rb', line 156

def class_name
  @class_name ||= (options[:class_name] || derive_class_name).to_s
end

#inverse_ofObject



175
176
177
178
179
# File 'lib/active_record/reflection.rb', line 175

def inverse_of
  return unless inverse_name

  @inverse_of ||= klass._reflect_on_association inverse_name
end

#join_keys(assoc_klass) ⇒ Object



162
163
164
# File 'lib/active_record/reflection.rb', line 162

def join_keys(assoc_klass)
  JoinKeys.new(foreign_key, active_record_primary_key)
end

#primary_key_typeObject



148
149
150
# File 'lib/active_record/reflection.rb', line 148

def primary_key_type
  klass.type_for_attribute(klass.primary_key)
end

#quoted_table_nameObject



144
145
146
# File 'lib/active_record/reflection.rb', line 144

def quoted_table_name
  klass.quoted_table_name
end

#source_macroObject



166
167
168
169
170
171
172
173
# File 'lib/active_record/reflection.rb', line 166

def source_macro
  ActiveSupport::Deprecation.warn(<<-MSG.squish)
    ActiveRecord::Base.source_macro is deprecated and will be removed
    without replacement.
  MSG

  macro
end

#table_nameObject

:nodoc:



134
135
136
# File 'lib/active_record/reflection.rb', line 134

def table_name
  klass.table_name
end