diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-05-19 16:11:37 -0400 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-05-19 16:11:53 -0400 |
commit | 0e12300c5e685ddc1b26c99fdb790e54a93153d5 (patch) | |
tree | cec92a22e0039845b8f9e0fc8c5a2b81175a4660 /activerecord/lib | |
parent | 21a60c15cca12c03f6c9e7500b9d1a4eaa05db1a (diff) | |
download | rails-0e12300c5e685ddc1b26c99fdb790e54a93153d5.tar.gz rails-0e12300c5e685ddc1b26c99fdb790e54a93153d5.tar.bz2 rails-0e12300c5e685ddc1b26c99fdb790e54a93153d5.zip |
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)
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 12 |
2 files changed, 9 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 94f59f9e95..a3c30642d0 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1722,7 +1722,7 @@ module ActiveRecord 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 @@ module ActiveRecord 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 diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 1b0ae2c942..5360db6a19 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -69,9 +69,11 @@ module ActiveRecord 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 @@ module ActiveRecord 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 @@ module ActiveRecord 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 |