-
Hi The way it would work is that a collection has a The code would look something like this {
name: "version",
label: "Version",
type: "number",
required: true,
defaultValue: 0,
validate: (value, opts) => {
console.log(
"validating version",
value,
"data",
opts.data,
"op",
opts.operation,
);
if (opts.operation !== "create" && opts.data?.version !== value) {
return "Optimistic locking error";
}
},
admin: { hidden: false, readOnly: true },
hooks: {
beforeChange: [
(args) => {
// cannot change the version here as this runs BEFORE the validation.
},
],
afterChange: [
(args) => {
// while this runs after validation , it also runs after saving therefore, any change here is not persisted
return args.value + 1;
},
],
},
}, So my problem is that the current order of hooks is
I would need a hook that allows me to update the value before the save operation but AFTER validation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
this seems to work better in payload 3 |
Beta Was this translation helpful? Give feedback.
this seems to work better in payload 3