Skip to content

Commit

Permalink
Added no_returning option for Postgres to insert without RETURNING cl…
Browse files Browse the repository at this point in the history
…ause

Drop unnecessary empty line in method
  • Loading branch information
makaroni4 committed Jun 12, 2016
1 parent bcf8eba commit fe7a119
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 @@ -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

Expand Down

0 comments on commit fe7a119

Please sign in to comment.