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.



130
131
132
# File 'lib/active_record/reflection.rb', line 130

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

#class_nameObject

Returns the class name for the macro.

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



146
147
148
# File 'lib/active_record/reflection.rb', line 146

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

#join_keys(assoc_klass) ⇒ Object



152
153
154
# File 'lib/active_record/reflection.rb', line 152

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

#primary_key_typeObject



138
139
140
# File 'lib/active_record/reflection.rb', line 138

def primary_key_type
  klass.type_for_attribute(klass.primary_key)
end

#quoted_table_nameObject



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

def quoted_table_name
  klass.quoted_table_name
end

#source_macroObject



156
157
158
159
160
161
162
163
# File 'lib/active_record/reflection.rb', line 156

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:



124
125
126
# File 'lib/active_record/reflection.rb', line 124

def table_name
  klass.table_name
end