Skip to content

feat: many to many relations#24

Merged
0xcadams merged 3 commits intomainfrom
many-to-many-relations
Jan 13, 2025
Merged

feat: many to many relations#24
0xcadams merged 3 commits intomainfrom
many-to-many-relations

Conversation

@0xcadams
Copy link
Member

Added many to many relations through a junction table:

export const schema = createSchema(
  createZeroSchema(drizzleSchema, {
    version: 1,
    tables: {
      user: {
        id: true,
        name: true,
      },
      group: {
        id: true,
        name: true,
      },
      users_to_group: {
        user_id: true,
        group_id: true,
      },
    },
    manyToMany: {
      // The origin table to define the many-to-many relationship on
      user: {
        // The key is the relation name and value is [junction table, target table]
        groups: ["users_to_group", "group"],
      },
    },
  }),
);

@0xcadams 0xcadams merged commit 1d1e263 into main Jan 13, 2025
2 checks passed
@0xcadams 0xcadams deleted the many-to-many-relations branch January 13, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant