Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

deprecating "insert"

  • Loading branch information...
commit baa660f62b4fae9197d7b4b6e4bbcf4059d106a8 1 parent 39ccb80
@tenderlove tenderlove authored
View
5 History.txt
@@ -4,6 +4,11 @@
* AST is now Enumerable
+* Deprecations
+
+ * Calls to `insert` are deprecated. Please use `compile_insert` then call
+ `to_sql` on the resulting object and execute that SQL.
+
== 2.0.6 12/01/2010
* Bug Fixes
View
16 lib/arel/crud.rb
@@ -20,11 +20,21 @@ def update values
@engine.connection.update um.to_sql, 'AREL'
end
- # FIXME: this method should go away
- def insert values
+ def compile_insert values
im = InsertManager.new @engine
im.insert values
- @engine.connection.insert im.to_sql
+ 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 2.2.0. Please
+switch to `compile_insert`
+ eowarn
+ end
+ @engine.connection.insert compile_insert(values).to_sql
end
def delete
View
4 lib/arel/table.rb
@@ -108,6 +108,10 @@ def select_manager
SelectManager.new(@engine)
end
+ def insert_manager
+ InsertManager.new(@engine)
+ end
+
private
def attributes_for columns
View
2  test/helper.rb
@@ -8,6 +8,6 @@
class Object
def must_be_like other
- self.gsub(/\s+/, ' ').strip.must_equal other.gsub(/\s+/, ' ').strip
+ gsub(/\s+/, ' ').strip.must_equal other.gsub(/\s+/, ' ').strip
end
end
View
12 test/test_table.rb
@@ -6,6 +6,18 @@ module Arel
@relation = Table.new(:users)
end
+ it 'should return an insert manager' do
+ im = @relation.compile_insert 'VALUES(NULL)'
+ assert_kind_of Arel::InsertManager, im
+ assert_equal 'INSERT INTO NULL VALUES(NULL)', im.to_sql
+ end
+
+ it 'should return IM from insert_manager' do
+ im = @relation.insert_manager
+ assert_kind_of Arel::InsertManager, im
+ assert_equal im.engine, @relation.engine
+ end
+
describe 'skip' do
it 'should add an offset' do
sm = @relation.skip 2
Please sign in to comment.
Something went wrong with that request. Please try again.