Class: ActiveRecord::Reflection::AbstractReflection
- Inherits:
-
Object
- Object
- ActiveRecord::Reflection::AbstractReflection
- Defined in:
- lib/active_record/reflection.rb
Overview
Holds all the methods that are shared between MacroReflection, AssociationReflection and ThroughReflection
Direct Known Subclasses
Defined Under Namespace
Classes: JoinKeys
Instance Method Summary collapse
-
#build_association(attributes, &block) ⇒ Object
Returns a new, unsaved instance of the associated class.
-
#class_name ⇒ Object
Returns the class name for the macro.
- #join_keys(assoc_klass) ⇒ Object
- #primary_key_type ⇒ Object
- #quoted_table_name ⇒ Object
- #source_macro ⇒ Object
-
#table_name ⇒ Object
:nodoc:.
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_name ⇒ Object
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 ||= ([: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_type ⇒ Object
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_name ⇒ Object
134 135 136 |
# File 'lib/active_record/reflection.rb', line 134 def quoted_table_name klass.quoted_table_name end |
#source_macro ⇒ Object
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_name ⇒ Object
:nodoc:
124 125 126 |
# File 'lib/active_record/reflection.rb', line 124 def table_name klass.table_name end |