From fe7a119e275bb57ba3475040a34e2f643eeb7599 Mon Sep 17 00:00:00 2001 From: Anatoli Makarevich Date: Fri, 13 May 2016 14:40:41 +0200 Subject: [PATCH] Added no_returning option for Postgres to insert without RETURNING clause Drop unnecessary empty line in method --- .../adapters/postgresql_adapter.rb | 2 +- test/support/postgresql/import_examples.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/activerecord-import/adapters/postgresql_adapter.rb b/lib/activerecord-import/adapters/postgresql_adapter.rb index 3ce83da5..ccfd8b7a 100644 --- a/lib/activerecord-import/adapters/postgresql_adapter.rb +++ b/lib/activerecord-import/adapters/postgresql_adapter.rb @@ -26,7 +26,7 @@ def next_value_for_sequence(sequence_name) end def post_sql_statements( table_name, options ) # :nodoc: - if options[:primary_key].blank? + if options[:no_returning] || options[:primary_key].blank? super(table_name, options) else super(table_name, options) << "RETURNING #{options[:primary_key]}" diff --git a/test/support/postgresql/import_examples.rb b/test/support/postgresql/import_examples.rb index 0b601cd3..c978c056 100644 --- a/test/support/postgresql/import_examples.rb +++ b/test/support/postgresql/import_examples.rb @@ -147,6 +147,20 @@ def should_support_postgresql_import_functionality end end end + + describe "no_returning" do + let(:books) { [Book.new(author_name: "foo", title: "bar")] } + + it "creates records" do + assert_difference "Book.count", +1 do + Book.import books, no_returning: true + end + end + + it "returns no ids" do + assert_equal [], Book.import(books, no_returning: true).ids + end + end end end