@@ -362,7 +362,12 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
362362 }
363363 this . artifactInfo . indexesToBeUpdated =
364364 this . artifactInfo . indexesToBeUpdated || [ ] ;
365-
365+ const relations = [ ] ;
366+ const repositoryConfigs = {
367+ datasource : '' ,
368+ repositories : new Set ( ) ,
369+ repositoryBaseClass : 'DefaultCrudRepository' ,
370+ } ;
366371 // eslint-disable-next-line @typescript-eslint/prefer-for-of
367372 for ( let i = 0 ; i < this . artifactInfo . modelDefinitions . length ; i ++ ) {
368373 const modelDefinition = this . artifactInfo . modelDefinitions [ i ] ;
@@ -391,23 +396,18 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
391396 ) ;
392397 // If targetModel is not in discovered models, skip creating relation
393398 if ( targetModel ) {
394- Object . assign ( templateData . properties [ relation . foreignKey ] , {
395- relation,
396- } ) ;
397- if ( ! relationImports . includes ( relation . type ) ) {
398- relationImports . push ( relation . type ) ;
399- }
400- relationDestinationImports . push ( relation . model ) ;
401-
402- foreignKeys [ relationName ] = { } ;
403- Object . assign ( foreignKeys [ relationName ] , {
404- name : relationName ,
405- entity : relation . model ,
406- entityKey : Object . entries ( targetModel . properties ) . find (
407- x => x ?. [ 1 ] . id === 1 ,
408- ) ?. [ 0 ] ,
409- foreignKey : relation . foreignKey ,
410- } ) ;
399+ const configs = { } ;
400+ configs [ 'sourceModel' ] = templateData . name ;
401+ configs [ 'destinationModel' ] = targetModel . name ;
402+ configs [ 'foreignKeyName' ] = relation . foreignKey ;
403+ configs [ 'relationType' ] = relation . type ;
404+ configs [ 'registerInclusionResolver' ] = true ;
405+ configs [ 'yes' ] = true ;
406+ relations . push ( configs ) ;
407+ repositoryConfigs [ 'datasource' ] =
408+ this . options . datasource || this . options . dataSource ;
409+ repositoryConfigs . repositories . add ( templateData . name ) ;
410+ repositoryConfigs . repositories . add ( targetModel . name ) ;
411411 }
412412 }
413413 // remove model import if the model relation is with itself
@@ -462,6 +462,8 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
462462 // This part at the end is just for the ArtifactGenerator
463463 // end message to output something nice, before it was "Discover undefined was created in src/models/"
464464 this . artifactInfo . type = 'Models' ;
465+ this . artifactInfo . relationConfigs = relations ;
466+ this . artifactInfo . repositoryConfigs = repositoryConfigs ;
465467 this . artifactInfo . name = this . artifactInfo . modelDefinitions
466468 . map ( d => d . name )
467469 . join ( ',' ) ;
0 commit comments