aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2014-07-14 18:37:59 -0400
committereileencodes <eileencodes@gmail.com>2014-07-17 08:47:08 -0400
commit8c263d53b3b9d190a8ae564ca043b96b76c76877 (patch)
treeb2012b76c98777589cd25da3f5ec1cec3f62d7b1 /activerecord
parentb062d5d9671de59490dffd0ff18f650e22528756 (diff)
downloadrails-8c263d53b3b9d190a8ae564ca043b96b76c76877.tar.gz
rails-8c263d53b3b9d190a8ae564ca043b96b76c76877.tar.bz2
rails-8c263d53b3b9d190a8ae564ca043b96b76c76877.zip
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.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/reflection.rb25
1 files 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
# <tt>has_many :clients</tt> returns <tt>:clients</tt>
attr_reader :name
- # Returns the macro type.
- #
- # <tt>composed_of :balance, class_name: 'Money'</tt> returns <tt>:composed_of</tt>
- # <tt>has_many :clients</tt> returns <tt>:has_many</tt>
- 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.
+ #
+ # <tt>has_many :clients</tt> returns <tt>:has_many</tt>
+ 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