From 7b3d85db4c58e2f719981efd6ef5a6b870f6ab49 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 13 Nov 2009 15:30:51 -0800 Subject: Revert "Split arel_table into method to get a relation and another to memoize the default relation." This reverts commit bd51790895fc75a3b4e19e8dd7aa6dc389d77068. --- activerecord/lib/active_record/associations.rb | 4 ++-- .../associations/has_and_belongs_to_many_association.rb | 4 ++-- .../lib/active_record/associations/has_many_association.rb | 2 +- activerecord/lib/active_record/base.rb | 12 ++++++------ activerecord/lib/active_record/calculations.rb | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index fc18b53b9d..6c5e25010f 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1698,7 +1698,7 @@ module ActiveRecord def construct_finder_arel_with_included_associations(options, join_dependency) scope = scope(:find) - relation = arel_table_for((scope && scope[:from]) || options[:from]) + relation = arel_table((scope && scope[:from]) || options[:from]) for association in join_dependency.join_associations relation = association.join_relation(relation) @@ -1741,7 +1741,7 @@ module ActiveRecord def construct_finder_sql_for_association_limiting(options, join_dependency) scope = scope(:find) - relation = arel_table_for(options[:from]) + relation = arel_table(options[:from]) for association in join_dependency.join_associations relation = association.join_relation(relation) diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index ce4e96637b..c646fe488b 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -56,7 +56,7 @@ module ActiveRecord if @reflection.options[:insert_sql] @owner.connection.insert(interpolate_sql(@reflection.options[:insert_sql], record)) else - relation = arel_table_for(@reflection.options[:join_table]) + relation = arel_table(@reflection.options[:join_table]) attributes = columns.inject({}) do |attrs, column| case column.name.to_s when @reflection.primary_key_name.to_s @@ -82,7 +82,7 @@ module ActiveRecord if sql = @reflection.options[:delete_sql] records.each { |record| @owner.connection.delete(interpolate_sql(sql, record)) } else - relation = arel_table_for(@reflection.options[:join_table]) + relation = arel_table(@reflection.options[:join_table]) relation.conditions(relation[@reflection.primary_key_name].eq(@owner.id). and(Arel::Predicates::In.new(relation[@reflection.association_foreign_key], records.map(&:id))) ).delete diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index 36a668c284..cd31b0e211 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -69,7 +69,7 @@ module ActiveRecord when :delete_all @reflection.klass.delete(records.map { |record| record.id }) else - relation = arel_table_for(@reflection.table_name) + relation = arel_table(@reflection.table_name) relation.conditions(relation[@reflection.primary_key_name].eq(@owner.id). and(Arel::Predicates::In.new(relation[@reflection.klass.primary_key], records.map(&:id))) ).update(relation[@reflection.primary_key_name] => nil) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 778c36361d..056f29f029 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1493,11 +1493,11 @@ module ActiveRecord #:nodoc: def arel_table(table = nil) - @arel_table ||= arel_table_for(table_name) - end - - def arel_table_for(table_name) - Relation.new(self, Arel::Table.new(table_name)) + table = table_name if table.blank? + if @arel_table.nil? || @arel_table.name != table + @arel_table = Relation.new(self, Arel::Table.new(table)) + end + @arel_table end private @@ -1666,7 +1666,7 @@ module ActiveRecord #:nodoc: def construct_finder_arel(options = {}, scope = scope(:find)) # TODO add lock to Arel - relation = arel_table_for(options[:from]). + relation = arel_table(options[:from]). joins(construct_join(options[:joins], scope)). conditions(construct_conditions(options[:conditions], scope)). select(options[:select] || (scope && scope[:select]) || default_select(options[:joins] || (scope && scope[:joins]))). diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index 46545d96a3..40242333e5 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -146,7 +146,7 @@ module ActiveRecord join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, merged_includes, construct_join(options[:joins], scope)) construct_finder_arel_with_included_associations(options, join_dependency) else - relation = arel_table_for(options[:from]). + relation = arel_table(options[:from]). joins(construct_join(options[:joins], scope)). conditions(construct_conditions(options[:conditions], scope)). order(options[:order]). @@ -164,7 +164,7 @@ module ActiveRecord def execute_simple_calculation(operation, column_name, options, relation) #:nodoc: column = if column_names.include?(column_name.to_s) - Arel::Attribute.new(arel_table_for(options[:from] || table_name), + Arel::Attribute.new(arel_table(options[:from] || table_name), options[:select] || column_name) else Arel::SqlLiteral.new(options[:select] || -- cgit v1.2.3