Permalink
Browse files

keep track of the left and right reflections and expose those

  • Loading branch information...
1 parent 7963c5d commit d3089adb1a76d0d0446e914e972cf3ef49964333 @tenderlove tenderlove committed Oct 2, 2013
@@ -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
@@ -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

0 comments on commit d3089ad

Please sign in to comment.