diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-02 15:49:36 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-02 15:49:36 -0700 |
commit | 8e4afa4eb1bd64cdfa3689df7a06e5148e063364 (patch) | |
tree | 0e79f8047c72c2ea5bf4b46ab5118bc388ba4484 /activerecord/lib/active_record | |
parent | dca2fb368096735d18ea5b881e08816f7d552044 (diff) | |
download | rails-8e4afa4eb1bd64cdfa3689df7a06e5148e063364.tar.gz rails-8e4afa4eb1bd64cdfa3689df7a06e5148e063364.tar.bz2 rails-8e4afa4eb1bd64cdfa3689df7a06e5148e063364.zip |
repurpose the HABTM builder class
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations.rb | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb | 25 |
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 |