1 import { BaseRelationship } from "./base"
2 import { RelationNullableModifier } from "./nullable"
3
4 /**
5 * HasOne relationship defines a relationship between two entities
6 * where the owner of the relationship has exactly one instance
7 * of the related entity.
8 *
9 * For example: A user HasOne profile
10 *
11 * You may use the "BelongsTo" relationship to define the inverse
12 * of the "HasOne" relationship
13 */
14 export class HasOne<T> extends BaseRelationship<T> {
15 type = "hasOne" as const
16
17 static isHasOne<T>(relationship: any): relationship is HasOne<T> {
18 return relationship?.type === "hasOne"
19 }
20
21 /**
22 * Apply nullable modifier on the schema
23 */
24 nullable() {
25 return new RelationNullableModifier<T, HasOne<T>, false>(this)
26 }
27 }