Configure Many-to-Many relationships
mainDrizzle-zero supports many-to-many relationships via junction tables. You can configure them using either a Simple or Extended format in your drizzle-zero.config.ts.
Simple Configuration
Use this when you have a standard junction table. The format is [junction_table, target_table].
Extended Configuration
Use this for complex scenarios like self-referential relationships. You must explicitly map the sourceField, destTable, and destField.
Example of Extended Configuration (Self-referential):
export default drizzleZeroConfig(drizzleSchema, {
tables: {
user: { id: true, name: true },
friendship: { requestingId: true, acceptingId: true },
},
manyToMany: {
user: {
friends: [
{
sourceField: ['id'],
destTable: 'friendship',
destField: ['requestingId'],
},
{
sourceField: ['acceptingId'],
destTable: 'user',
destField: ['id'],
},
],
},
},
});// Simple format example
export default drizzleZeroConfig(drizzleSchema, {
tables: {
user: { id: true, name: true },
usersToGroup: { userId: true, groupId: true },
group: { id: true, name: true },
},
manyToMany: {
user: {
groups: ['usersToGroup', 'group'],
},
},
});