aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb')
-rw-r--r--activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb15
1 files changed, 13 insertions, 2 deletions
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 4b47824148..2f79976594 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
@@ -80,6 +80,19 @@ module ActiveRecord::Associations::Builder
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 @@ module ActiveRecord::Associations::Builder
middle_options
end
- private
-
def belongs_to_options(options)
rhs_options = {}