Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

repurpose the HABTM builder class

  • Loading branch information...
commit 8e4afa4eb1bd64cdfa3689df7a06e5148e063364 1 parent dca2fb3
Aaron Patterson tenderlove authored
7 activerecord/lib/active_record/associations.rb
View
@@ -130,7 +130,6 @@ module Builder #:nodoc:
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 @@ def has_and_belongs_to_many(name, scope = nil, options = {}, &extension)
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 @@ def destroy_associations
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
25 activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
View
@@ -1,5 +1,5 @@
module ActiveRecord::Associations::Builder
- class HABTM
+ class HasAndBelongsToMany # :nodoc:
class JoinTableResolver
KnownTable = Struct.new :join_table
@@ -118,27 +118,4 @@ def belongs_to_options(options)
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
Please sign in to comment.
Something went wrong with that request. Please try again.