Skip to content

Commit

Permalink
Merge pull request #276 from makaroni4/master
Browse files Browse the repository at this point in the history
Added no_returning option for Postgres to insert without RETURNING clause
  • Loading branch information
zdennis authored Jun 22, 2016
2 parents 121c098 + fe7a119 commit db02550
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/activerecord-import/adapters/postgresql_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"
Expand Down
14 changes: 14 additions & 0 deletions test/support/postgresql/import_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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

Expand Down

0 comments on commit db02550

Please sign in to comment.