-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
setNext used within a pre-save hook works but generates an error #45
Comments
correction ! Counters are incremented but sequence counter is not set properly in all employees documents. Missing in some, those for which the error shows up in the log. further correction : not linked to the fact that there is two counters. Same happens with just employees_counter / sequence. |
hi Fabrizio Looking further into this and getting deeper in pre-save hook documentation, I found out that the issue comes from the save you do in the setNext method. A very little change would then allow to use the setNext method in a pre-save hook as I wish to :
I hope you will agree that this is a minor change which provide a major benefit : allowing to set counters on demand in pre-save hook. |
Hello @rernens. |
hi Fabrizio yes I will make the pull request and submit the code change, straight away. |
… pre-save hook
Hi Fabrizio, Have you had a chance to review my PR ? I works fine for me but I had like to get it committed to the base code in order to be able to update my other dependencies. Thanks in advance |
Any update on this? We also need the ability to use setNext in a pre save hook. I personally think setNext should not call save by default. Thanks! |
There was a PR about this but it didn't pass the tests and now it may be outdated. Have a look at the PR to see if you can use the code from @rernens directly. |
@ramiel
hi Fabrizio
Pursuing previous exchange on scoped counter, I have the requirement in my application to manage when a counter is incremented when a new document is added.
I have seen that the setNext method is made just for this and looking at your code, I see that it invokes the same function than what you normally do in the pre-save hook that you attach to the schema in order to increment the counter for a new document.
In my case, each new document should not get a specific counter incremented.
In fact, due to legal reasons, employees documents in my application can't be updated in place. In order to keep the previous value of the document, the current document is marked as archived, a new document is created as a clone of the one just archived and changes are applied to this new document.
As employees must have a unique sequence number, the counter should not be incremented in this case. So if a value already exists in the sequence attribute the sequence number should not be set with a new value, leaving all employees documents for a specific employee with the same sequence counter value but a different updateSequence counter incremented at each update.
Here below is what I have implemented :
Counters are well incremented as expected.
A new employees_counter value is set in the sequence attribute when a new employee is created as well as 1 in the updateSequence.
When an employee is udpated, a new document is created, the sequence remains the same and the updateSequence receive an incremented value.
So far so good.
But the rest api console displays the following message when a new employee is created :
Could it be that there might be a conflict between the automatic update of the updateSequence counter and the manual update of the sequence counter.
Am I doing something wrong ?
The text was updated successfully, but these errors were encountered: