Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

have the builder create the middle reflection

  • Loading branch information...
commit 7963c5d841c2c518d1087558f51a904060a9d305 1 parent 0af978d
@tenderlove tenderlove authored
View
13 activerecord/lib/active_record/associations.rb
@@ -1574,18 +1574,9 @@ def has_and_belongs_to_many1(name, scope = nil, options = {}, &extension)
join_model = builder.through_model
- middle_name = [self.name.downcase.pluralize, name].join('_').gsub(/::/, '_').to_sym
-
- middle_options = builder.middle_options join_model
-
- hm_builder = Builder::HasMany.create_builder(self,
- middle_name,
- nil,
- middle_options)
- middle_reflection = hm_builder.build self
+ middle_reflection = builder.middle_reflection join_model
Builder::HasMany.define_callbacks self, middle_reflection
-
Reflection.add_reflection self, middle_reflection.name, middle_reflection
include Module.new {
@@ -1599,7 +1590,7 @@ def destroy_associations
}
hm_options = {}
- hm_options[:through] = middle_name
+ hm_options[:through] = middle_reflection.name
hm_options[:source] = join_model.right_association_name
[:before_add, :after_add, :before_remove, :after_remove].each do |k|
View
15 activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
@@ -80,6 +80,19 @@ def self.add_right_association(name, options)
join_model
end
+ def middle_reflection(join_model)
+ middle_name = [lhs_model.name.downcase.pluralize,
+ association_name].join('_').gsub(/::/, '_').to_sym
+ middle_options = middle_options join_model
+ hm_builder = HasMany.create_builder(lhs_model,
+ middle_name,
+ nil,
+ middle_options)
+ hm_builder.build lhs_model
+ end
+
+ private
+
def middle_options(join_model)
middle_options = {}
middle_options[:class] = join_model
@@ -90,8 +103,6 @@ def middle_options(join_model)
middle_options
end
- private
-
def belongs_to_options(options)
rhs_options = {}
Please sign in to comment.
Something went wrong with that request. Please try again.