aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations.rb
diff options
context:
space:
mode:
authorArthur Neves <arthurnn@gmail.com>2014-05-24 14:51:58 -0400
committerArthur Neves <arthurnn@gmail.com>2014-05-26 17:05:21 -0400
commit00b024218f1c91fde1217ae4951bd2c817bc9ea9 (patch)
tree15d8f87209a058c901e357703b0e6150bb11b025 /activerecord/lib/active_record/associations.rb
parent6259e4e2dcca9a79f22f96658c33efe81936bc0d (diff)
downloadrails-00b024218f1c91fde1217ae4951bd2c817bc9ea9.tar.gz
rails-00b024218f1c91fde1217ae4951bd2c817bc9ea9.tar.bz2
rails-00b024218f1c91fde1217ae4951bd2c817bc9ea9.zip
Refactoring .reflections public method.
Now the internal reflections will hold a reference to its public representation, so when the outside world calls `Account.reflection` we can build a list of public reflections.
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rw-r--r--activerecord/lib/active_record/associations.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 68a386f8db..07dfc448e7 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1577,6 +1577,8 @@ module ActiveRecord
scope = nil
end
+ habtm_reflection = ActiveRecord::Reflection::AssociationReflection.new(:has_and_belongs_to_many, name, scope, options, self)
+
builder = Builder::HasAndBelongsToMany.new name, self, options
join_model = builder.through_model
@@ -1590,6 +1592,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]
include Module.new {
class_eval <<-RUBY, __FILE__, __LINE__ + 1
@@ -1610,9 +1613,7 @@ module ActiveRecord
end
has_many name, scope, hm_options, &extension
-
- reflection = ActiveRecord::Reflection::AssociationReflection.new(:has_and_belongs_to_many, name, scope, options, self)
- self.reflections = self.reflections.except(middle_reflection.name).merge!(name.to_s => reflection)
+ self._reflections[name.to_s].parent_reflection = [name.to_s, habtm_reflection]
end
end
end