From d3089adb1a76d0d0446e914e972cf3ef49964333 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Oct 2013 15:43:22 -0700 Subject: [PATCH] keep track of the left and right reflections and expose those --- activerecord/lib/active_record/associations.rb | 2 +- .../associations/builder/has_and_belongs_to_many.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 69ed7cc078..09ed85ef24 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1591,7 +1591,7 @@ def destroy_associations hm_options = {} hm_options[:through] = middle_reflection.name - hm_options[:source] = join_model.right_association_name + hm_options[:source] = join_model.right_reflection.name [:before_add, :after_add, :before_remove, :after_remove].each do |k| if options.key? k 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 2f79976594..8df7e7857f 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 @@ -46,8 +46,8 @@ class << self; attr_accessor :class_resolver attr_accessor :name attr_accessor :table_name_resolver - attr_accessor :left_association_name - attr_accessor :right_association_name + attr_accessor :left_reflection + attr_accessor :right_reflection end def self.table_name @@ -59,14 +59,14 @@ def self.compute_type(class_name) end def self.add_left_association(name, options) - self.left_association_name = name belongs_to name, options + self.left_reflection = reflect_on_association(name) end def self.add_right_association(name, options) rhs_name = name.to_s.singularize.to_sym - self.right_association_name = rhs_name belongs_to rhs_name, options + self.right_reflection = reflect_on_association(rhs_name) end } @@ -96,7 +96,7 @@ def middle_reflection(join_model) def middle_options(join_model) middle_options = {} middle_options[:class] = join_model - middle_options[:source] = join_model.left_association_name + middle_options[:source] = join_model.left_reflection.name if options.key? :foreign_key middle_options[:foreign_key] = options[:foreign_key] end -- GitLab