From cfa5f491459328139c7a3e88d42cfe9a7637e939 Mon Sep 17 00:00:00 2001 From: Dan Kochetov Date: Wed, 31 May 2023 23:36:54 +0300 Subject: [PATCH] Allow using named self-relations --- drizzle-orm/src/relations.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drizzle-orm/src/relations.ts b/drizzle-orm/src/relations.ts index df4322358..8eff11791 100644 --- a/drizzle-orm/src/relations.ts +++ b/drizzle-orm/src/relations.ts @@ -431,7 +431,8 @@ export function normalizeRelation( const reverseRelations: Relation[] = []; for (const referencedTableRelation of Object.values(referencedTableFields.relations)) { if ( - (relation.relationName && referencedTableRelation.relationName === relation.relationName) + (relation.relationName && relation !== referencedTableRelation + && referencedTableRelation.relationName === relation.relationName) || (!relation.relationName && referencedTableRelation.referencedTable === relation.sourceTable) ) { reverseRelations.push(referencedTableRelation);