aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/associations.rb7
-rw-r--r--activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb25
2 files changed, 3 insertions, 29 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 5988af59d8..7c393d9028 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -130,7 +130,6 @@ module ActiveRecord
autoload :HasOne, 'active_record/associations/builder/has_one'
autoload :HasMany, 'active_record/associations/builder/has_many'
autoload :HasAndBelongsToMany, 'active_record/associations/builder/has_and_belongs_to_many'
- autoload :HABTM, 'active_record/associations/builder/has_and_belongs_to_many'
end
eager_autoload do
@@ -1566,7 +1565,7 @@ module ActiveRecord
scope = nil
end
- builder = Builder::HABTM.new name, self, options
+ builder = Builder::HasAndBelongsToMany.new name, self, options
join_model = builder.through_model
@@ -1590,9 +1589,7 @@ module ActiveRecord
hm_options[:source] = join_model.right_reflection.name
[:before_add, :after_add, :before_remove, :after_remove].each do |k|
- if options.key? k
- hm_options[k] = options[k]
- end
+ hm_options[k] = options[k] if options.key? k
end
has_many name, scope, hm_options, &extension
diff --git a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
index 8df7e7857f..b4537c5564 100644
--- a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
+++ b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
@@ -1,5 +1,5 @@
module ActiveRecord::Associations::Builder
- class HABTM
+ class HasAndBelongsToMany # :nodoc:
class JoinTableResolver
KnownTable = Struct.new :join_table
@@ -118,27 +118,4 @@ module ActiveRecord::Associations::Builder
rhs_options
end
end
-
- class HasAndBelongsToMany < CollectionAssociation #:nodoc:
- def macro
- :has_and_belongs_to_many
- end
-
- def valid_options
- super + [:join_table, :association_foreign_key]
- end
-
- def self.define_callbacks(model, reflection)
- super
- name = reflection.name
- model.send(:include, Module.new {
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
- def destroy_associations
- association(:#{name}).delete_all
- super
- end
- RUBY
- })
- end
- end
end