@@ -331,6 +331,7 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
331331 if ( this . options . relations ) {
332332 const relationImports = [ ] ;
333333 const relationDestinationImports = [ ] ;
334+ const foreignKeys = { } ;
334335 for ( const relationName in templateData . settings . relations ) {
335336 const relation = templateData . settings . relations [ relationName ] ;
336337 const targetModel = this . artifactInfo . modelDefinitions . find (
@@ -343,12 +344,25 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
343344 } ) ;
344345 relationImports . push ( relation . type ) ;
345346 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+ } ) ;
346357 }
347358 }
348359 templateData . relationImports = relationImports ;
349360 templateData . relationDestinationImports = relationDestinationImports ;
350361 // Delete relation from modelSettings
351362 delete templateData . settings . relations ;
363+ if ( Object . keys ( foreignKeys ) ?. length > 0 ) {
364+ Object . assign ( templateData . settings , { foreignKeys} ) ;
365+ }
352366 templateData . modelSettings = utils . stringifyModelSettings (
353367 templateData . settings ,
354368 ) ;
0 commit comments