Skip to content

nullableIdType

nullableIdType<Brand>(codec, options?): () => Type<Id<Brand> | null, string | null>

Defined in: src/adapters/mikro-orm.ts:148

Factory that returns a MikroORM Type subclass for a nullable Id<Brand> column.

Behaves like idType but convertToJSValue returns null for null / undefined database values and convertToDatabaseValue normalises null and undefined to null. Use for optional foreign keys.

Brand extends string

IdColumnCodec<Brand>

The brand-scoped codec used to parse values read from the database.

Optional column configuration.

string

SQL column type to use (default: "text"). Pass "varchar(30)" or "char(26)" to match an existing DDL or index strategy. The value is passed through verbatim — no validation is performed.

() => Type<Id<Brand> | null, string | null>

import { Property } from "@mikro-orm/core";
import { nullableIdType } from "@smonn/ids/mikro-orm";
import { createTimestampId } from "@smonn/ids";
import type { Id } from "@smonn/ids";
const usr = createTimestampId("usr");
class Post {
@Property({ type: nullableIdType(usr), nullable: true })
authorId!: Id<"usr"> | null;
}
// explicit varchar column
class Comment {
@Property({ type: nullableIdType(usr, { columnType: "varchar(30)" }), nullable: true })
authorId!: Id<"usr"> | null;
}