Permalink
Browse files

Merge pull request #15595 from eileencodes/abstract-away-habtm-macro

Abstract away use of HABTM macro
  • Loading branch information...
tenderlove committed Jun 9, 2014
2 parents 3fe33a3 + 9eb87fb commit 32b6873d0899ab185bc862db09c18fcaed88bdb3
Showing with 9 additions and 2 deletions.
  1. +1 −1 activerecord/lib/active_record/associations.rb
  2. +8 −1 activerecord/lib/active_record/reflection.rb
@@ -1577,7 +1577,7 @@ def has_and_belongs_to_many(name, scope = nil, options = {}, &extension)
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
@@ -228,7 +228,7 @@ def klass
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 @@ def primary_key(klass)
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:

0 comments on commit 32b6873

Please sign in to comment.