Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove HABTM special cases from reflections

  • Loading branch information...
commit 957d7ae037b156e69c5999e48038b5c6b7235159 1 parent a03ea3f
Aaron Patterson tenderlove authored
Showing with 2 additions and 14 deletions.
  1. +2 −14 activerecord/lib/active_record/reflection.rb
16 activerecord/lib/active_record/reflection.rb
View
@@ -12,8 +12,6 @@ module Reflection # :nodoc:
def self.create(macro, name, scope, options, ar)
case macro
- when :has_and_belongs_to_many
- klass = AssociationReflection
when :has_many, :belongs_to, :has_one
klass = options[:through] ? ThroughReflection : AssociationReflection
when :composed_of
@@ -196,7 +194,7 @@ def klass
def initialize(macro, name, scope, options, active_record)
super
- @collection = [:has_many, :has_and_belongs_to_many].include?(macro)
+ @collection = :has_many == macro
@automatic_inverse_of = nil
@type = options[:as] && "#{options[:as]}_type"
@foreign_type = options[:foreign_type] || "#{name}_type"
@@ -256,10 +254,6 @@ def counter_cache_column
def check_validity!
check_validity_of_inverse!
-
- if has_and_belongs_to_many? && association_foreign_key == foreign_key
- raise HasAndBelongsToManyAssociationForeignKeyNeeded.new(self)
- end
end
def check_validity_of_inverse!
@@ -341,10 +335,6 @@ def belongs_to?
macro == :belongs_to
end
- def has_and_belongs_to_many?
- macro == :has_and_belongs_to_many
- end
-
def association_class
case macro
when :belongs_to
@@ -353,8 +343,6 @@ def association_class
else
Associations::BelongsToAssociation
end
- when :has_and_belongs_to_many
- Associations::HasAndBelongsToManyAssociation
when :has_many
if options[:through]
Associations::HasManyThroughAssociation
@@ -604,7 +592,7 @@ def source_macro
# A through association is nested if there would be more than one join table
def nested?
- chain.length > 2 || through_reflection.has_and_belongs_to_many?
+ chain.length > 2
end
# We want to use the klass from this reflection, rather than just delegate straight to
Please sign in to comment.
Something went wrong with that request. Please try again.