From 8c263d53b3b9d190a8ae564ca043b96b76c76877 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Mon, 14 Jul 2014 18:37:59 -0400 Subject: Remove need for macro instance var Same as we did for collection, removed the `@macro` instance var and it is now set in each association. Unfortunately it can't be left undefined in AssociationReflection so it has to be set there. For now I am setting it to NotImplementedError since there is no default macro and it changes based on the reflection type. --- activerecord/lib/active_record/reflection.rb | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 12208aecf7..2eefba2dfe 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -177,12 +177,6 @@ module ActiveRecord # has_many :clients returns :clients attr_reader :name - # Returns the macro type. - # - # composed_of :balance, class_name: 'Money' returns :composed_of - # has_many :clients returns :has_many - attr_reader :macro - attr_reader :scope # Returns the hash of options used for the macro. @@ -386,7 +380,7 @@ Joining, Preloading and eager loading of these associations is deprecated and wi scope ? [[scope]] : [[]] end - alias :source_macro :macro + def source_macro; macro; end def has_inverse? inverse_name @@ -408,6 +402,11 @@ Joining, Preloading and eager loading of these associations is deprecated and wi end end + # Returns the macro type. + # + # has_many :clients returns :has_many + def macro; raise NotImplementedError; end + # Returns whether or not this association reflection is for a collection # association. Returns +true+ if the +macro+ is either +has_many+ or # +has_and_belongs_to_many+, +false+ otherwise. @@ -578,10 +577,11 @@ Joining, Preloading and eager loading of these associations is deprecated and wi class HasManyReflection < AssociationReflection #:nodoc: def initialize(name, scope, options, active_record) - @macro = :has_many super(name, scope, options, active_record) end + def macro; :has_many; end + def collection? true end @@ -589,24 +589,27 @@ Joining, Preloading and eager loading of these associations is deprecated and wi class HasOneReflection < AssociationReflection #:nodoc: def initialize(name, scope, options, active_record) - @macro = :has_one super(name, scope, options, active_record) end + + def macro; :has_one; end end class BelongsToReflection < AssociationReflection #:nodoc: def initialize(name, scope, options, active_record) - @macro = :belongs_to super(name, scope, options, active_record) end + + def macro; :belongs_to; end end class HasAndBelongsToManyReflection < AssociationReflection #:nodoc: def initialize(name, scope, options, active_record) - @macro = :has_and_belongs_to_many super end + def macro; :has_and_belongs_to_many; end + def collection? true end -- cgit v1.2.3