File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
packages/runtime/src/client/helpers Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -46,17 +46,17 @@ export class SchemaDbPusher<Schema extends SchemaDef> {
4646 if ( model . baseModel ) {
4747 // base model should be created before concrete model
4848 const baseDef = requireModel ( this . schema , model . baseModel ) ;
49- // edge: base model -> concrete model
50- graph . push ( [ baseDef , model ] ) ;
49+ // edge: concrete model -> base model
50+ graph . push ( [ model , baseDef ] ) ;
5151 added = true ;
5252 }
5353
5454 for ( const field of Object . values ( model . fields ) ) {
5555 // relation order
5656 if ( field . relation && field . relation . fields && field . relation . references ) {
5757 const targetModel = requireModel ( this . schema , field . type ) ;
58- // edge: relation target model -> fk model
59- graph . push ( [ targetModel , model ] ) ;
58+ // edge: fk side -> target model
59+ graph . push ( [ model , targetModel ] ) ;
6060 added = true ;
6161 }
6262 }
@@ -67,7 +67,9 @@ export class SchemaDbPusher<Schema extends SchemaDef> {
6767 }
6868 }
6969
70- return toposort ( graph ) . filter ( ( m ) => ! ! m ) ;
70+ return toposort ( graph )
71+ . reverse ( )
72+ . filter ( ( m ) => ! ! m ) ;
7173 }
7274
7375 private createModelTable ( kysely : ToKysely < Schema > , modelDef : ModelDef ) {
You can’t perform that action at this time.
0 commit comments