aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-06-09 16:19:07 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-06-09 16:19:07 -0700
commit32b6873d0899ab185bc862db09c18fcaed88bdb3 (patch)
tree6b9b189081b23d4f2be5f2e482648c9b0ce4cee2
parent3fe33a318f29c03966ca5892413884414421108c (diff)
parent9eb87fbf15b2bb68d9d16c83dfe46f88d89a915c (diff)
downloadrails-32b6873d0899ab185bc862db09c18fcaed88bdb3.tar.gz
rails-32b6873d0899ab185bc862db09c18fcaed88bdb3.tar.bz2
rails-32b6873d0899ab185bc862db09c18fcaed88bdb3.zip
Merge pull request #15595 from eileencodes/abstract-away-habtm-macro
Abstract away use of HABTM macro
-rw-r--r--activerecord/lib/active_record/associations.rb2
-rw-r--r--activerecord/lib/active_record/reflection.rb9
2 files changed, 9 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 07dfc448e7..1d1201a838 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1577,7 +1577,7 @@ module ActiveRecord
scope = nil
end
- habtm_reflection = ActiveRecord::Reflection::AssociationReflection.new(:has_and_belongs_to_many, name, scope, options, self)
+ habtm_reflection = ActiveRecord::Reflection::HABTMReflection.new(:has_and_belongs_to_many, name, scope, options, self)
builder = Builder::HasAndBelongsToMany.new name, self, options
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 4d5203612c..3433ac8203 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -228,7 +228,7 @@ module ActiveRecord
def initialize(macro, name, scope, options, active_record)
super
- @collection = [:has_many, :has_and_belongs_to_many].include?(macro)
+ @collection = macro == :has_many
@automatic_inverse_of = nil
@type = options[:as] && "#{options[:as]}_type"
@foreign_type = options[:foreign_type] || "#{name}_type"
@@ -538,6 +538,13 @@ Joining, Preloading and eager loading of these associations is deprecated and wi
end
end
+ class HABTMReflection < AssociationReflection #:nodoc:
+ def initialize(macro, name, scope, options, active_record)
+ super
+ @collection = true
+ end
+ end
+
# Holds all the meta-data about a :through association as it was specified
# in the Active Record class.
class ThroughReflection < AssociationReflection #:nodoc: