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.
Type Parameters
Section titled “Type Parameters”Brand extends string
Parameters
Section titled “Parameters”IdColumnCodec<Brand>
The brand-scoped codec used to parse values read from the database.
options?
Section titled “options?”Optional column configuration.
columnType?
Section titled “columnType?”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.
Returns
Section titled “Returns”() => Type<Id<Brand> | null, string | null>
Example
Section titled “Example”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 columnclass Comment { @Property({ type: nullableIdType(usr, { columnType: "varchar(30)" }), nullable: true }) authorId!: Id<"usr"> | null;}