-
Notifications
You must be signed in to change notification settings - Fork 84
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
bulk_insert does not return a worker object #66
Comments
hi @fredwillmore , it looks like the behaviour you are describing is covered by unit tests https://github.com/jamis/bulk_insert/blob/master/test/bulk_insert_test.rb . Can you confirm you can reproduce it consistently? |
I was surprised by this as well. The test sets an outer bulk_insert/test/bulk_insert_test.rb Lines 9 to 13 in ab5db08
However, the README indicates that a worker would be returned when using a block. Lines 176 to 192 in ab5db08
As mentioned in the original issue comment, the worker is only returned if no values are present and no block is given. bulk_insert/lib/bulk_insert.rb Lines 11 to 25 in ab5db08
I think it should be appropriate to always return the worker. Maybe something like this? def bulk_insert #…
# …
if values.present?
transaction do
worker.add_all(values)
worker.save!
end
elsif block_given?
transaction do
yield worker
worker.save!
end
else
worker
end |
I don't remember exactly. :/ However, looking at the diff, I suspect it was an attempt to make the return value consistent, so that it always returns either a worker object, or |
I am using version 1.8.1, ruby 2.3.8, rails 4.2.5
I am trying to use non-block mode, passing an array of attribute hashes. My model is named
Gap
:however,
bulk_insert
returnsnil
. (block mode also returns nil).Looking at the code it looks like it only returns a worker if
bulk_insert
is only called without values or a block:How would I access the worker object in order to look at
result_sets
?thanks, fw
The text was updated successfully, but these errors were encountered: