Skip to main content
Version: 2.0.0

Schema Options

The second argument to new Schema((b) => ..., { ... }) configures schema-wide behavior. These options apply to every create, update, and delete operation.

note

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.

Loading playground…

sanitizeError

Transform the error payload before it is returned from create or update.

Loading playground…

onDelete

Global listener(s) invoked by model.delete. Receives the full entity and context options.

Loading playground…

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.

Loading playground…

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.

Loading playground…

ignore

Ignore input fields when the handler returns true. Only lax and virtual fields can be ignored at the schema level.

Loading playground…

ignoreUpdate

Ignore update values for the listed fields when the handler returns true. Works with lax, required, and virtual fields.

Loading playground…

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.

Loading playground…

timestamps

Enable createdAt and updatedAt automatically.

  • true — uses createdAt and updatedAt keys.
  • { 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.

Loading playground…

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,
});
OptionDescription
equalityDepthNesting depth for value comparisons during updates.
sanitizeErrorTransform the error payload before returning it.
onDeleteGlobal listener(s) for model.delete.
onSuccessGlobal listener(s) after a successful create/update.
postValidateCross-field validation after per-field validators.
ignoreIgnore input fields when the handler returns true.
ignoreUpdateIgnore update values for the listed fields when the handler returns true.
requiredCross-field required constraint for lax/virtual fields.
timestampsEnable createdAt/updatedAt automatically.