Permalink
Browse files

use update.key instead of update.ast.key. make better use of select m…

…anager.
  • Loading branch information...
1 parent e85c644 commit eff8aeeff35a7fb1b60fab8d67050695eb44c6a3 @jonleighton jonleighton committed Aug 11, 2011
@@ -338,9 +338,9 @@ def sanitize_limit(limit)
# 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
@@ -606,18 +606,14 @@ def limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key)
# 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
@@ -512,18 +512,14 @@ def add_limit_offset!(sql, options) #:nodoc:
# 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

0 comments on commit eff8aee

Please sign in to comment.