/** * Relationship builders for `@atlex/orm`. * * A `RelationBuilder` is a thin wrapper around `QueryBuilder` that captures * relationship metadata used for eager loading and provides a typed, lazy API. */ import type { Model } from '../Model.js'; import type { QueryBuilder } from '../QueryBuilder.js'; export type RelationType = 'hasOne' | 'hasMany' | 'belongsTo' | 'belongsToMany' | 'hasManyThrough' | 'hasOneThrough'; export interface RelationMeta { type: RelationType; name: string; parent: Model; related: typeof Model; foreignKey?: string; localKey?: string; ownerKey?: string; pivotTable?: string; pivotForeignKey?: string; pivotRelatedKey?: string; } export declare class RelationBuilder { protected readonly query: QueryBuilder; protected readonly meta: RelationMeta; constructor(query: QueryBuilder, meta: RelationMeta); /** * Access underlying query builder. * * @returns The wrapped `QueryBuilder`. * @example * user.posts().getQuery().latest().limit(10) */ getQuery(): QueryBuilder; /** * Relationship metadata (used for eager loading). * * @returns Metadata. */ getMeta(): RelationMeta; /** * Fetch related models. * * @returns Related models. * @example * const posts = await user.posts().get() */ get(): Promise; /** * Fetch the first related model. * * @returns First related model or null. * @example * const profile = await user.profile().first() */ first(): Promise; /** * Fetch the first related model or fail. */ firstOrFail(): Promise; /** * Pass-through to underlying query builder methods. * This keeps relations lazy by default. */ select(...columns: string[]): this; where(column: string, operator: string, value: unknown): this; where(column: string, value: unknown): this; where(callback: (qb: QueryBuilder) => void): this; orderBy(column: string, direction?: 'asc' | 'desc'): this; latest(column?: string): this; limit(n: number): this; } //# sourceMappingURL=RelationBuilder.d.ts.map