aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-08-11 08:38:47 +0100
committerJon Leighton <j@jonathanleighton.com>2011-08-15 23:10:16 +0100
commit12aaad0848fb29bf64025043a855b0c0b497a6b8 (patch)
treebadfa9a1b8d817266d472aaf171c15f9a5ca67bc /activerecord/lib
parent8778c82e32690ed7b25664522d0bd0324ebea840 (diff)
downloadrails-12aaad0848fb29bf64025043a855b0c0b497a6b8.tar.gz
rails-12aaad0848fb29bf64025043a855b0c0b497a6b8.tar.bz2
rails-12aaad0848fb29bf64025043a855b0c0b497a6b8.zip
use update.key instead of update.ast.key. make better use of select manager.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb20
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql_adapter.rb20
3 files changed, 18 insertions, 26 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
index d8bd33f72a..bfbf953a37 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -311,9 +311,9 @@ module ActiveRecord
# an UPDATE statement, so in the mysql adapters we redefine this to do that.
def join_to_update(update, select) #:nodoc:
subselect = select.ast.clone
- subselect.cores.last.projections = [update.ast.key]
+ subselect.cores.last.projections = [update.key]
- update.where update.ast.key.in(subselect)
+ update.where update.key.in(subselect)
end
protected
diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
index 460745fba0..379ba162ed 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
@@ -584,18 +584,14 @@ module ActiveRecord
# in the form of a subsubquery. Ugh!
def join_to_update(update, select) #:nodoc:
if select.limit || select.offset || select.orders.any?
- subsubselect = select.ast.clone
- subsubselect.cores.last.projections = [update.ast.key]
- subsubselect = Arel::Nodes::TableAlias.new(
- Arel::Nodes::Grouping.new(subsubselect),
- '__active_record_temp'
- )
-
- subselect = Arel::Nodes::SelectCore.new
- subselect.from = subsubselect
- subselect.projections << Arel::Table.new('__active_record_temp')[update.ast.key.name]
-
- update.where update.ast.key.in(subselect)
+ subsubselect = select.clone
+ subsubselect.ast.cores.last.projections = [update.key]
+
+ subselect = Arel::SelectManager.new(select.engine)
+ subselect.project Arel.sql(update.key.name)
+ subselect.from subsubselect.as('__active_record_temp')
+
+ update.where update.key.in(subselect)
else
update.table select.ast.cores.last.source
update.wheres = select.constraints
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index 4581c16d25..a33e2d8cb0 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -498,18 +498,14 @@ module ActiveRecord
# in the form of a subsubquery. Ugh!
def join_to_update(update, select) #:nodoc:
if select.limit || select.offset || select.orders.any?
- subsubselect = select.ast.clone
- subsubselect.cores.last.projections = [update.ast.key]
- subsubselect = Arel::Nodes::TableAlias.new(
- Arel::Nodes::Grouping.new(subsubselect),
- '__active_record_temp'
- )
-
- subselect = Arel::Nodes::SelectCore.new
- subselect.from = subsubselect
- subselect.projections << Arel::Table.new('__active_record_temp')[update.ast.key.name]
-
- update.where update.ast.key.in(subselect)
+ subsubselect = select.clone
+ subsubselect.ast.cores.last.projections = [update.key]
+
+ subselect = Arel::SelectManager.new(select.engine)
+ subselect.project Arel.sql(update.key.name)
+ subselect.from subsubselect.as('__active_record_temp')
+
+ update.where update.key.in(subselect)
else
update.table select.ast.cores.last.source
update.wheres = select.constraints