aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-07-22 18:28:54 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-07-22 18:28:54 -0700
commitd531ac0b9afcce02d5cd81006c45dad2fb813e22 (patch)
tree5be336db4791996852671878130aca68cdcb0cd2 /activerecord
parente20dd73df42d63b206d221e2258cc6dc7b1e6068 (diff)
downloadrails-d531ac0b9afcce02d5cd81006c45dad2fb813e22.tar.gz
rails-d531ac0b9afcce02d5cd81006c45dad2fb813e22.tar.bz2
rails-d531ac0b9afcce02d5cd81006c45dad2fb813e22.zip
AR::Base does not need to know how to create reflection objects
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/aggregations.rb2
-rw-r--r--activerecord/lib/active_record/associations/builder/association.rb2
-rw-r--r--activerecord/lib/active_record/reflection.rb38
3 files changed, 21 insertions, 21 deletions
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb
index 9d1c12ec62..d597fa26cf 100644
--- a/activerecord/lib/active_record/aggregations.rb
+++ b/activerecord/lib/active_record/aggregations.rb
@@ -223,7 +223,7 @@ module ActiveRecord
reader_method(name, class_name, mapping, allow_nil, constructor)
writer_method(name, class_name, mapping, allow_nil, converter)
- create_reflection(:composed_of, part_id, nil, options, self)
+ ActiveRecord::Reflection.create(:composed_of, part_id, nil, options, self)
end
private
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb
index 3e1f699f58..297b7ce6d3 100644
--- a/activerecord/lib/active_record/associations/builder/association.rb
+++ b/activerecord/lib/active_record/associations/builder/association.rb
@@ -54,7 +54,7 @@ module ActiveRecord::Associations::Builder
validate_options
define_accessors
configure_dependency if options[:dependent]
- reflection = model.create_reflection(macro, name, scope, options, model)
+ reflection = ActiveRecord::Reflection.create(macro, name, scope, options, model)
Association.extensions.each do |extension|
extension.build @model, reflection
end
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index f470946da5..471ed13a1c 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -10,6 +10,25 @@ module ActiveRecord
self.aggregate_reflections = {}
end
+ def self.create(macro, name, scope, options, ar)
+ case macro
+ when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
+ klass = options[:through] ? ThroughReflection : AssociationReflection
+ when :composed_of
+ klass = AggregateReflection
+ end
+
+ reflection = klass.new(macro, name, scope, options, ar)
+
+ if klass == AggregateReflection
+ ar.aggregate_reflections = ar.aggregate_reflections.merge(name => reflection)
+ else
+ ar.reflections = ar.reflections.merge(name => reflection)
+ end
+
+ reflection
+ end
+
# \Reflection enables to interrogate Active Record classes and objects
# about their associations and aggregations. This information can,
# for example, be used in a form builder that takes an Active Record object
@@ -19,25 +38,6 @@ module ActiveRecord
# MacroReflection class has info for AggregateReflection and AssociationReflection
# classes.
module ClassMethods
- def create_reflection(macro, name, scope, options, active_record)
- case macro
- when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
- klass = options[:through] ? ThroughReflection : AssociationReflection
- when :composed_of
- klass = AggregateReflection
- end
-
- reflection = klass.new(macro, name, scope, options, active_record)
-
- if klass == AggregateReflection
- self.aggregate_reflections = self.aggregate_reflections.merge(name => reflection)
- else
- self.reflections = self.reflections.merge(name => reflection)
- end
-
- reflection
- end
-
# Returns an array of AggregateReflection objects for all the aggregations in the class.
def reflect_on_all_aggregations
aggregate_reflections.values