@@ -331,6 +331,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
331
331
if ( this . options . relations ) {
332
332
const relationImports = [ ] ;
333
333
const relationDestinationImports = [ ] ;
334
+ const foreignKeys = { } ;
334
335
for ( const relationName in templateData . settings . relations ) {
335
336
const relation = templateData . settings . relations [ relationName ] ;
336
337
const targetModel = this . artifactInfo . modelDefinitions . find (
@@ -343,12 +344,25 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
343
344
} ) ;
344
345
relationImports . push ( relation . type ) ;
345
346
relationDestinationImports . push ( relation . model ) ;
347
+
348
+ foreignKeys [ relationName ] = { } ;
349
+ Object . assign ( foreignKeys [ relationName ] , {
350
+ name : relationName ,
351
+ entity : relation . model ,
352
+ entityKey : Object . entries ( targetModel . properties ) . find (
353
+ x => x ?. [ 1 ] . id === 1 ,
354
+ ) ?. [ 0 ] ,
355
+ foreignKey : relation . foreignKey ,
356
+ } ) ;
346
357
}
347
358
}
348
359
templateData . relationImports = relationImports ;
349
360
templateData . relationDestinationImports = relationDestinationImports ;
350
361
// Delete relation from modelSettings
351
362
delete templateData . settings . relations ;
363
+ if ( Object . keys ( foreignKeys ) ?. length > 0 ) {
364
+ Object . assign ( templateData . settings , { foreignKeys} ) ;
365
+ }
352
366
templateData . modelSettings = utils . stringifyModelSettings (
353
367
templateData . settings ,
354
368
) ;
0 commit comments