The join table class.
class CustomerStore extends JoinTable<Customer, Store> {
public readonly customerId: ForeignKey<Customer>;
public readonly storeId: ForeignKey<Store>;
}
// Link a Customer to a Store only if the Store is in Springfield
const condition: JoinTableCondition<CustomerStore> = {
storeId: { target: { "address.city": "Springfield" } }
};
The condition
JoinTable.createandJoinTable.deleteaccept, keyed by the join table's foreign key properties.A join table has no row of its own, so each key guards the entity its foreign key references, wrapped in
targetto make clear that the condition applies to that entity's row rather than to the key's value. Each target is typed from the foreign key's own type parameter, so the key must be declaredForeignKey<Target>: on a bareForeignKeythe guard is a compile error naming the missing type parameter (see UntypedForeignKeyTargetError).Each
targettakes a TargetCondition on the referenced entity, in the full query-filter vocabulary,nulland$orincluded. A guard also requires its entity to exist, even withreferentialIntegrityCheck: false. When a guard fails, theWriteConditionFailedErrornames the join table as itsentityand the join table's keys as itsid, for examplecustomerId=customer-1, storeId=store-1.