-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
if create fails, it still auto increment #7
Comments
Hi @proton, I'm looking to take this on. What do you think of changing https://github.com/proton/mongoid_auto_increment/blob/master/lib/mongoid_auto_increment.rb#L17 to |
@0sc can you tell me more? |
@proton my understanding is that if create fails the |
@0sc so what you propose? |
As per this issue, I suggest using |
@0sc so you want make it in two transactions? I prefer keep atomicity. |
I'm not sure I understand what you mean. Activerecord callbacks are executed within a single database transaction (See the transaction section here). Maybe I'm missing something but switching from |
@0sc it's not ActiveRecord :) |
Ahh, my bad I was looking at the wrong docs. But why will switching from |
There are no transactions in mongoid :3 |
I have the following code
class SizeList
include Mongoid::Document
field :_id, type: Integer
field :name
auto_increment :sequence, :seed => -1, :step => 1
before_create { self.id = self.sequence }
end
I want the sequence to be continuous. This works really well, except in the case when create fails. It should decrease the sequence in such cases.
You should probably use after_add callback to increase the auto increment value.
Although i can still live with it.
The text was updated successfully, but these errors were encountered: