1 import { BaseRelationship } from "./base"
2 import { RelationNullableModifier } from "./nullable"
3
4 export class BelongsTo<
5 T,
6 const OptionalForeignKeyName extends string | undefined = undefined
7 > extends BaseRelationship<T> {
8 type = "belongsTo" as const
9 declare $foreignKey: true
10 declare $foreignKeyName: OptionalForeignKeyName
11
12 static isBelongsTo<T>(relationship: any): relationship is BelongsTo<T, any> {
13 return relationship?.type === "belongsTo"
14 }
15
16 /**
17 * Apply nullable modifier on the schema
18 */
19 nullable() {
20 return new RelationNullableModifier<
21 T,
22 BelongsTo<T, OptionalForeignKeyName>,
23 true
24 >(this)
25 }
26 }