Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added no_returning option for Postgres to insert without RETURNING clause #276

Merged
merged 1 commit into from
Jun 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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