Skip to content

egon-orm-workspace / egon-orm / Loaded

Type Alias: Loaded<S, P> ​

ts
type Loaded<S, P> = LoadedUnchecked<S, P>;

Defined in: core/src/contracts/schema.ts:962

A row of schema S with the associations in P loaded: Row plus one property per loaded association, to any depth.

  • hasMany and manyToMany become an array of the target's rows.
  • hasOne becomes the target's row or null.
  • belongsTo becomes the target's row, or | null when the foreign-key field is nullable. The foreign key is the foreignKey given to belongsTo, by default <association name>Id; when it cannot be determined the result is | null.

Type Parameters ​

S ​

S extends AnySchema

P ​

P extends PreloadSpec<S>

Example ​

ts
declare const Comment: AnySchema;
declare const Post: AnySchema & { comments: Assoc<"hasMany", typeof Comment> };
declare const User: AnySchema & { posts: Assoc<"hasMany", typeof Post> };

declare const user: Loaded<typeof User, { posts: "comments" }>;
user.posts[0]?.comments; // Row<typeof Comment>[] | undefined