1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/arel/crud.rb
Aaron Patterson d7ff05e240 Merge branch '2-0-stable'
* 2-0-stable:
  making sure limit is correctly copied to update manager
2011-01-03 15:57:06 -08:00

68 lines
1.5 KiB
Ruby

module Arel
###
# FIXME hopefully we can remove this
module Crud
def compile_update values
um = UpdateManager.new @engine
if Nodes::SqlLiteral === values
relation = @ctx.from
else
relation = values.first.first.relation
end
um.table relation
um.set values
um.take @ast.limit.expr if @ast.limit
um.order(*@ast.orders)
um.wheres = @ctx.wheres
um
end
# FIXME: this method should go away
def update values
if $VERBOSE
warn <<-eowarn
update (#{caller.first}) is deprecated and will be removed in ARel 3.0.0. Please
switch to `compile_update`
eowarn
end
um = compile_update values
@engine.connection.update um.to_sql, 'AREL'
end
def compile_insert values
im = InsertManager.new @engine
im.insert values
im
end
# FIXME: this method should go away
def insert values
if $VERBOSE
warn <<-eowarn
insert (#{caller.first}) is deprecated and will be removed in ARel 3.0.0. Please
switch to `compile_insert`
eowarn
end
@engine.connection.insert compile_insert(values).to_sql
end
def compile_delete
dm = DeleteManager.new @engine
dm.wheres = @ctx.wheres
dm.from @ctx.froms
dm
end
def delete
if $VERBOSE
warn <<-eowarn
delete (#{caller.first}) is deprecated and will be removed in ARel 3.0.0. Please
switch to `compile_delete`
eowarn
end
@engine.connection.delete compile_delete.to_sql, 'AREL'
end
end
end