aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/reflection.rb
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2014-07-21 17:50:31 -0400
committereileencodes <eileencodes@gmail.com>2014-07-30 20:16:27 -0400
commit8d7dea766e7a5371dab09bf4c819ff1fc28ffa31 (patch)
tree6f24208eddb58a78b13a14f2dd9508ab2f5c73a2 /activerecord/lib/active_record/reflection.rb
parent20a277c9a2a2f1bb0ff2a77d52f7e9590dbae8ac (diff)
downloadrails-8d7dea766e7a5371dab09bf4c819ff1fc28ffa31.tar.gz
rails-8d7dea766e7a5371dab09bf4c819ff1fc28ffa31.tar.bz2
rails-8d7dea766e7a5371dab09bf4c819ff1fc28ffa31.zip
Redefine macro checks for reflections
Now that we define the macro on the reflection type we no longer need to check `macro == :what` on each type for `belongs_to?` or `has_one?` etc. These now default to false unless it's defined in the reflection class. Reuse existing belongs_to? method to check macros We don't need to do `:belongs_to == macro` anymore becasue we have a `belongs_to?` method. I didn't find this being used anywhere for `has_one?` or `collection?` since they were already fixed.
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r--activerecord/lib/active_record/reflection.rb16
1 files changed, 7 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 1672128aa3..21da011e8a 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -431,14 +431,10 @@ Joining, Preloading and eager loading of these associations is deprecated and wi
end
# Returns +true+ if +self+ is a +belongs_to+ reflection.
- def belongs_to?
- macro == :belongs_to
- end
+ def belongs_to?; false; end
# Returns +true+ if +self+ is a +has_one+ reflection.
- def has_one?
- macro == :has_one
- end
+ def has_one?; false; end
def association_class
case macro
@@ -585,9 +581,7 @@ Joining, Preloading and eager loading of these associations is deprecated and wi
def macro; :has_many; end
- def collection?
- true
- end
+ def collection?; true; end
end
class HasOneReflection < AssociationReflection #:nodoc:
@@ -596,6 +590,8 @@ Joining, Preloading and eager loading of these associations is deprecated and wi
end
def macro; :has_one; end
+
+ def has_one?; true; end
end
class BelongsToReflection < AssociationReflection #:nodoc:
@@ -604,6 +600,8 @@ Joining, Preloading and eager loading of these associations is deprecated and wi
end
def macro; :belongs_to; end
+
+ def belongs_to?; true; end
end
class HasAndBelongsToManyReflection < AssociationReflection #:nodoc: