Skip to content

Type Alias: ManyToManyConfiguration<OM, TM, PKT, JM, JPKT, JPKF, FM, PKF>

ts
type ManyToManyConfiguration<OM, TM, PKT, JM, JPKT, JPKF, FM, PKF> =
  | [typeof ManyToMany, FM]
  | [typeof ManyToMany, FM, JM]
  | [typeof ManyToMany, FM, JM, JPKT]
  | [typeof ManyToMany, FM, JM, JPKT, JPKF]
  | [typeof ManyToMany, FM, JM, JPKT, JPKF, PKF]
  | [typeof ManyToMany, FM, JM, JPKT, JPKF, PKF, PKT];

The configuration for a ManyToMany 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
JM extends StringKeyOf<OM>the table of the join model
JPKT extends StringKeyOf<OM[JM]>the property used as the foreign key in the join model that references the originating model
JPKF extends StringKeyOf<OM[JM]>the property used as the foreign key in the join model that references the foreign 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: {
         skills: [ManyToMany, 'skills', 'user_skills', 'user_id', 'skill_id'], 
        }
      },
      skills: {
        schema: '++id, name',
        properties: ['id', 'name'],
        relationships: {
         users: [ManyToMany, 'users'], 
        }
      }
      user_skills: {
        schema: '++id, user_id, skill_id, notes',
        properties: ['id', 'user_id', 'skill_id', 'notes'],
      }
  },
  ...
}