You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Combining a reference in a table schema (foreign key constraint) with a one-to-many relation for the same two tables defined in the constraint causes the seeder to duplicate these relations and enter an infinite loop.
4
+
5
+
Example:
6
+
7
+
```ts
8
+
// schema.ts
9
+
import { integer, pgTable, text } from"drizzle-orm/pg-core";
10
+
import { relations } from"drizzle-orm/relations";
11
+
12
+
exportconst users =pgTable("users", {
13
+
id: integer().primaryKey(),
14
+
name: text(),
15
+
email: text(),
16
+
});
17
+
18
+
exportconst posts =pgTable("posts", {
19
+
id: integer().primaryKey(),
20
+
content: text(),
21
+
userId: integer().references(() =>users.id),
22
+
});
23
+
24
+
exportconst postsRelation =relations(posts, ({ one }) => ({
25
+
user: one(users, {
26
+
fields: [posts.userId],
27
+
references: [users.id],
28
+
}),
29
+
}));
30
+
```
31
+
32
+
Now, seeding with the schema above will trigger a warning.
33
+
34
+
```
35
+
You are providing a one-to-many relation between the 'users' and 'posts' tables,
36
+
while the 'posts' table object already has foreign key constraint in the schema referencing 'users' table.
37
+
In this case, the foreign key constraint will be used.
0 commit comments