(relation: AnyRelation)
| 56 | } |
| 57 | |
| 58 | function validateRelation(relation: AnyRelation) { |
| 59 | if (!relation.implied && !relation.foreignKey) { |
| 60 | throw new Error( |
| 61 | `[${relation.name}] You must define foreign key for explicit relations due the limitations of Prisma.` |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | // ignore implied |
| 66 | if (relation.implied) return; |
| 67 | |
| 68 | if ( |
| 69 | relation.implying?.type === "one" && |
| 70 | !isCompositeColumnsUnique( |
| 71 | relation.referencer, |
| 72 | relation.on.map(([left]) => relation.referencer.columns[left]) |
| 73 | ) |
| 74 | ) { |
| 75 | throw new Error( |
| 76 | `[${relation.name}] one-to-one relations require both sides to be unique or primary key.` |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | if ( |
| 81 | !isCompositeColumnsUnique( |
| 82 | relation.table, |
| 83 | relation.on.map(([, right]) => relation.table.columns[right]) |
| 84 | ) |
| 85 | ) |
| 86 | throw new Error( |
| 87 | `[${relation.name}] For any explicit relations, the referenced columns must be unique or primary key.` |
| 88 | ); |
| 89 | } |
| 90 | |
| 91 | for (const table of tables) { |
| 92 | for (const foreignKey of table.foreignKeys) { |
no test coverage detected