Skip to content
VibORM
Esc
↑↓navigate↵open⌘Jpreview
On this page

Omitting Fields

Control model row projections, client defaults, and per-query projections

omit is the inverse of select: it returns every readable scalar except the ones you name.

const users = await client.user.findMany({
  omit: { passwordHash: true },
});
// { id: string; email: string; name: string }[]

Three owners

Layer Spelling Meaning Can a query undo it?
Model s.model({...}).omit({...}) Exclude the scalar from model row projections No
Client default defaultOmit({...}) Default projection on one derived client Yes
Query findMany({ omit: {...} }) Projection for one call —

Model .omit()

Model omit excludes a field from returned model rows. The field has no select or omit key and is not selected from the database:

const vault = s
  .model({ id: s.string().id(), label: s.string(), secret: s.string() })
  .omit({ secret: true });

Aggregates and groupBy can still return the field’s values, and filters, ordering, distinct and cursors can still use it. Do not use omit to protect a secret from callers who can choose query arguments. Enforce those permissions in your application or database.

Client defaultOmit()

defaultOmit() is the official extension for a derived client’s default projection. See Default omit for configuration, overrides, nested results, and extension ordering.

Query-level composition

Query omit works on operations returning model rows, including returning bulk writes. select first names the candidate result, then omit subtracts scalar fields. include adds relations, and every nested relation node owns its own projection:

await client.user.findMany({
  omit: { passwordHash: true },
  include: {
    posts: { omit: { draftBody: true } },
  },
});

An omit that removes every readable field is refused. A widened boolean makes the corresponding result key optional because runtime decides whether it is present.

Security boundary

Query omit and defaultOmit() are presentation defaults and are intentionally overridable. Model .omit() makes the row projection exclusion permanent, but none of the three authorizes access to fields, rows, relations or raw SQL. Use viborm/permissions for authorization rules enforced across the query graph. Its raw SQL and statement-transform boundaries still apply.

Was this page helpful?