aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-11-13 15:30:51 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2009-11-13 15:30:51 -0800
commit7b3d85db4c58e2f719981efd6ef5a6b870f6ab49 (patch)
tree571b86ca825c9fb09118c43449cf3f4fb50d2f32 /activerecord/lib/active_record
parent3f54f3100b6c262776ad324bd649ff268600e280 (diff)
downloadrails-7b3d85db4c58e2f719981efd6ef5a6b870f6ab49.tar.gz
rails-7b3d85db4c58e2f719981efd6ef5a6b870f6ab49.tar.bz2
rails-7b3d85db4c58e2f719981efd6ef5a6b870f6ab49.zip
Revert "Split arel_table into method to get a relation and another to memoize the default relation."
This reverts commit bd51790895fc75a3b4e19e8dd7aa6dc389d77068.
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb4
-rw-r--r--activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb4
-rw-r--r--activerecord/lib/active_record/associations/has_many_association.rb2
-rwxr-xr-xactiverecord/lib/active_record/base.rb12
-rw-r--r--activerecord/lib/active_record/calculations.rb4
5 files changed, 13 insertions, 13 deletions
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] ||