Schema Options
The second argument to new Schema((b) => ..., { ... }) configures schema-wide behavior. These options apply to every create, update, and delete operation.
Schema-level checks for postValidate run after individual field validators. Cross-field required constraints run during the required-field evaluation phase, before per-field validation. See Life cycles and Validators for more on execution order.
equalityDepth
Nesting depth used when comparing values for equality during updates. Default: 1.
A higher depth lets ivo detect changes inside nested objects and arrays, while 0 compares by reference and 1 compares one level deep.
sanitizeError
Transform the error payload before it is returned from create or update.
onDelete
Global listener(s) invoked by model.delete. Receives the full entity and context options.
onSuccess
Global listener(s) invoked after a successful create or update. Can be a function or a grouped config that only runs when one of the listed fields is involved.
postValidate
Run cross-field validation after individual field validators have finished. Each config needs at least two fields and a validator.
The validator receives the operation context and may return undefined/true/void for success, or an object mapping field names to errors. It can also return sanitized values under the validated key for each field.
ignore
Ignore input fields when the handler returns true. Only lax and virtual fields can be ignored at the schema level.
ignoreUpdate
Ignore update values for the listed fields when the handler returns true. Works with lax, required, and virtual fields.
required
Cross-field required constraint for lax and virtual fields. Use it when a field is only required depending on the value of another field.
The handler receives the operation context and returns an object mapping field names to errors, or undefined when no field is required.
timestamps
Enable createdAt and updatedAt automatically.
true— usescreatedAtandupdatedAtkeys.{ createdAt?: boolean | string, updatedAt?: boolean | string | { key?: string, nullable?: boolean } }— customize key names or disable one of them.
updatedAt is nullable by default on create.
Summary
new Schema((b) => ..., {
equalityDepth: 1,
sanitizeError: (payload, ctxOptions) => payload,
onDelete: [listener],
onSuccess: [listener],
postValidate: { fields: ["a", "b"], validator: ... },
ignore: { fields: ["secret"], handler: () => true },
ignoreUpdate: { fields: ["email"], handler: () => true },
required: { fields: ["email", "phone"], handler: ... },
timestamps: true,
});
| Option | Description |
|---|---|
equalityDepth | Nesting depth for value comparisons during updates. |
sanitizeError | Transform the error payload before returning it. |
onDelete | Global listener(s) for model.delete. |
onSuccess | Global listener(s) after a successful create/update. |
postValidate | Cross-field validation after per-field validators. |
ignore | Ignore input fields when the handler returns true. |
ignoreUpdate | Ignore update values for the listed fields when the handler returns true. |
required | Cross-field required constraint for lax/virtual fields. |
timestamps | Enable createdAt/updatedAt automatically. |