Skip to content

Type Alias: HasOneConfiguration<OM, TM, PKT, FM, PKF>

ts
type HasOneConfiguration<OM, TM, PKT, FM, PKF> =
  | [typeof HasOne, FM, Omit<OM[TM], PKT>]
  | [typeof HasOne, FM, Omit<OM[TM], PKT>, PKT]
  | [typeof HasOne, FM, Omit<OM[TM], PKT>, PKT, PKF];

The configuration for a HasOne relationship.

Type Parameters

Type ParameterDescription
OM extends Record<string, PlainObject>the map of all models in the database
TM extends StringKeyOf<OM>the table of the originating model
PKT extends StringKeyOf<OM[TM]>the property used as the primary key in the originating model
FM extends StringKeyOf<OM>the table of the foreign model
PKF extends StringKeyOf<OM[FM]>the property used as the primary key in the foreign model

Example

typescript
{
  ...
  models: {
      users: {
        schema: '++id, email, createdAt, updatedAt',
        properties: ['id', 'email', 'password'],
        primaryKey: 'id',
        relationships: {
          profile: [HasOne, 'profiles', 'user_id'], 
        }
      },
      profiles: {
        schema: '++id, user_id, full_name, avatar_url',
        properties: ['id', 'user_id', 'full_name', 'avatar_url'],
      }
  },
  ...
}