File tree Expand file tree Collapse file tree
packages/orm/src/client/helpers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,6 +84,10 @@ export class SchemaDbPusher<Schema extends SchemaDef> {
8484 for ( const field of Object . values ( model . fields ) ) {
8585 // relation order
8686 if ( field . relation && field . relation . fields && field . relation . references ) {
87+ // skip self-referential relations to avoid false cycle in toposort
88+ if ( field . type === model . name ) {
89+ continue ;
90+ }
8791 const targetModel = requireModel ( this . schema , field . type ) ;
8892 // edge: fk side -> target model
8993 graph . push ( [ model , targetModel ] ) ;
Original file line number Diff line number Diff line change 1+ import { createTestClient } from '@zenstackhq/testtools' ;
2+ import { describe , expect , it } from 'vitest' ;
3+
4+ // https://github.com/zenstackhq/zenstack/issues/2435
5+ describe ( 'Regression for issue 2435' , ( ) => {
6+ it ( 'should not throw cyclic dependency error when delegate model has a self-referential relation' , async ( ) => {
7+ await expect (
8+ createTestClient (
9+ `
10+ enum ContentType {
11+ POST
12+ ARTICLE
13+ QUESTION
14+ }
15+
16+ model Content {
17+ id Int @id @default(autoincrement())
18+ type ContentType
19+ @@delegate(type)
20+ }
21+
22+ model Post extends Content {
23+ post1s Post1[]
24+ replies Post[] @relation("PostReplies")
25+ parentId Int?
26+ parent Post? @relation("PostReplies", fields: [parentId], references: [id])
27+ }
28+
29+ model Post1 extends Content {
30+ post Post @relation(fields: [postId], references: [id])
31+ postId Int
32+ }
33+ ` ,
34+ ) ,
35+ ) . toResolveTruthy ( ) ;
36+ } ) ;
37+ } ) ;
You can’t perform that action at this time.
0 commit comments