Metakit / @doeixd/metakit/relation

define

function · packages/metakit/src/relation.ts:138

function define<Parent extends Schema.Top, Child extends Schema.Top>(config: {
  readonly name: string
  readonly parent: Parent
  readonly child: Child
  readonly foreignKey: KeySelector<Child['Type']>
  readonly parentKey?: KeySelector<Parent['Type']>
  readonly cardinality?: Cardinality
  readonly onDelete?: OnDelete
}): Relation<Child['Type']>

Declare a relation between a parent Schema and a child Schema: foreignKey selects the child's field(s) that point at the parent, and parentKey the parent's (default its id), one for one where the key is composite.