aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2014-12-09 14:29:50 -0500
committereileencodes <eileencodes@gmail.com>2015-01-02 17:15:31 -0500
commit16fafd658805407e2bda4f4bb06a70157c21f78a (patch)
treef84521e8b0c6f313c312417f3daf5e151eeca6f3 /activerecord/lib
parentcc9b813a821ef90d96405bf618fd691522a11ef9 (diff)
downloadrails-16fafd658805407e2bda4f4bb06a70157c21f78a.tar.gz
rails-16fafd658805407e2bda4f4bb06a70157c21f78a.tar.bz2
rails-16fafd658805407e2bda4f4bb06a70157c21f78a.zip
Move `alias_candiate` into `AbstractReflection`
This moves `alias_candidate` out of the `ReflectionProxy` and into the `AbstractReflection` so it is shared by all reflections. Change `alias_name` to a method and and remove assignment in `#get_chain`.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/association_scope.rb16
-rw-r--r--activerecord/lib/active_record/reflection.rb10
2 files changed, 16 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb
index 198a047e18..9d94822fc5 100644
--- a/activerecord/lib/active_record/associations/association_scope.rb
+++ b/activerecord/lib/active_record/associations/association_scope.rb
@@ -114,10 +114,12 @@ module ActiveRecord
end
class ReflectionProxy < SimpleDelegator
- attr_accessor :next, :alias_name
+ attr_accessor :next
+ attr_reader :alias_name
- def alias_candidate(name)
- "#{plural_name}_#{name}"
+ def initialize(reflection, alias_name)
+ super(reflection)
+ @alias_name = alias_name
end
end
@@ -125,14 +127,10 @@ module ActiveRecord
name = refl.name
runtime_reflection = ActiveRecord::Reflection::RuntimeReflection.new(refl, association)
alias_name = tracker.aliased_table_for(runtime_reflection.table_name, runtime_reflection.alias_candidate(name))
- runtime_reflection.alias_name = alias_name
prev = runtime_reflection
refl.chain.drop(1).each { |reflection|
- proxy = ReflectionProxy.new(reflection)
-
- alias_name = tracker.aliased_table_for(proxy.table_name, proxy.alias_candidate(name))
- proxy.alias_name = alias_name
-
+ alias_name = tracker.aliased_table_for(reflection.table_name, reflection.alias_candidate(name))
+ proxy = ReflectionProxy.new(reflection, alias_name)
prev.next = proxy
prev = proxy
}
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 79c6504a18..111911b575 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -165,6 +165,10 @@ module ActiveRecord
def constraints
scope_chain.flatten
end
+
+ def alias_candidate(name)
+ "#{plural_name}_#{name}"
+ end
end
# Base class for AggregateReflection and AssociationReflection. Objects of
@@ -936,7 +940,7 @@ module ActiveRecord
end
class RuntimeReflection < PolymorphicReflection
- attr_accessor :next, :alias_name
+ attr_accessor :next
def initialize(reflection, association)
@reflection = reflection
@@ -962,6 +966,10 @@ module ActiveRecord
def alias_candidate(name)
"#{plural_name}_#{name}_join"
end
+
+ def alias_name
+ Arel::Table.new(table_name)
+ end
end
end
end