parent_reflection should store only a reflection object
we should ask the reflection for its name rather than storing the reflection name in two places (an array and a reflection object)
This commit is contained in:
parent
21a60c15cc
commit
0e12300c5e
@ -1722,7 +1722,7 @@ def has_and_belongs_to_many(name, scope = nil, options = {}, &extension)
|
||||
|
||||
Builder::HasMany.define_callbacks self, middle_reflection
|
||||
Reflection.add_reflection self, middle_reflection.name, middle_reflection
|
||||
middle_reflection.parent_reflection = [name.to_s, habtm_reflection]
|
||||
middle_reflection.parent_reflection = habtm_reflection
|
||||
|
||||
include Module.new {
|
||||
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
||||
@ -1743,7 +1743,7 @@ def destroy_associations
|
||||
end
|
||||
|
||||
has_many name, scope, hm_options, &extension
|
||||
self._reflections[name.to_s].parent_reflection = [name.to_s, habtm_reflection]
|
||||
self._reflections[name.to_s].parent_reflection = habtm_reflection
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -69,9 +69,11 @@ def reflect_on_aggregation(aggregation)
|
||||
def reflections
|
||||
ref = {}
|
||||
_reflections.each do |name, reflection|
|
||||
parent_name, parent_reflection = reflection.parent_reflection
|
||||
if parent_name
|
||||
ref[parent_name] = parent_reflection
|
||||
parent_reflection = reflection.parent_reflection
|
||||
|
||||
if parent_reflection
|
||||
parent_name = parent_reflection.name
|
||||
ref[parent_name.to_s] = parent_reflection
|
||||
else
|
||||
ref[name] = reflection
|
||||
end
|
||||
@ -204,7 +206,7 @@ def initialize(name, scope, options, active_record)
|
||||
def autosave=(autosave)
|
||||
@automatic_inverse_of = false
|
||||
@options[:autosave] = autosave
|
||||
_, parent_reflection = self.parent_reflection
|
||||
parent_reflection = self.parent_reflection
|
||||
if parent_reflection
|
||||
parent_reflection.autosave = autosave
|
||||
end
|
||||
@ -272,7 +274,7 @@ def compute_class(name)
|
||||
end
|
||||
|
||||
attr_reader :type, :foreign_type
|
||||
attr_accessor :parent_reflection # [:name, Reflection]
|
||||
attr_accessor :parent_reflection # Reflection
|
||||
|
||||
def initialize(name, scope, options, active_record)
|
||||
super
|
||||
|
Loading…
Reference in New Issue
Block a user