[fixes #1004] Call beforeUpdate, beforeDestroy, beforeValidate callbacks with criteria#1328
[fixes #1004] Call beforeUpdate, beforeDestroy, beforeValidate callbacks with criteria#1328mmiller42 wants to merge 6 commits intobalderdashy:masterfrom
Conversation
… doesn't take 4 parameters
|
Hi @mmiller42! It looks like your pull request title doesn’t quite conform to our guidelines. Please edit the title so that it starts with [proposal], [patch], [fixes #], or [implements #]. Once you've fixed it, post a comment below (e.g. "ok, fixed!") and we'll take a look! |
|
ok, fixed! |
|
@mikermcneil commented on the original PR, which you can read here: #1122 (comment) The suggested change is to use a non-backwards-compatible This change requires changing several hundred unit tests, which I don't have the time for. Anyone who is looking for this feature: please comment on here if you'd like to be added as a collaborator to my fork, if you want to assist with making the suggested change. |
|
@mmiller42 what do you think of this syntax : this could minimize changes and provide an expandable options for next features... |
|
I like that syntax, though it's not up to me. Do you have any thoughts on it @mikermcneil, as a compromise? |
|
@mmiller42 any good reason why this PR was closed? It is still not yet in any upstream branches. |
|
For all people who need criteria in the lifecycles: https://github.com/sg-medien/sails-hook-lifecycle |
|
Hi ; indeed, putting criteria as second argument would not be backward compatible and it's dangerous. Why not put it at 3rd arg ?
|
|
Hi Greg, I changed a little bit code. For me it's working with two and three arguments ;) |
|
@DanielRuf I closed it because the method signature was not accepted and the suggested format required changing hundreds of unit tests as well as breaking backwards compatibility. @atiertant suggested a compromise that would be easy to implement but @mikermcneil never indicated approval so eventually I decided to close it as I'm not using Waterline anymore. @semy Nicely done!! 👍 @GregKapustin It is backwards compatible. When you pass a lifecycle listener to it, it detects whether your listener takes two or three arguments. If your listener has two arguments, it assumes the second is the callback, and if you pass it three, it assumes the second is the criteria and the third is the callback. In any case, I'm no longer maintaining this. If anyone's interested in fixing the tests to accommodate Mike's options dictionary, or in modifying it to use an alternate method signature as suggested by Alexandre, I'd be happy to transfer the repository. |
Pass criteria to the beforeUpdate, beforeDestroy, and beforeValidate callbacks, before the
callbackparam.In beforeValidate callbacks, criteria is
nullfor create operations.Serves as a solution to issue #1004.
NOTE: For backwards compatibility, it now checks if the beforeValidate or beforeCreate callback(s) only accept 3 arguments or beforeDestroy accepts only 2 and if so, passes the callback as the last argument and omits criteria.
Example usage and explanation:
Recreation of #1122.