@@ -283,30 +283,27 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
283283 for ( let i = 0 ; i < this . discoveringModels . length ; i ++ ) {
284284 const modelInfo = this . discoveringModels [ i ] ;
285285 debug ( `Discovering: ${ modelInfo . name } ...` ) ;
286- this . artifactInfo . modelDefinitions . push (
287- await modelMaker . discoverSingleModel (
288- this . artifactInfo . dataSource ,
289- modelInfo . name ,
290- {
291- schema : modelInfo . owner ,
292- disableCamelCase : this . artifactInfo . disableCamelCase ,
293- } ,
294- ) ,
286+ const modelDefinition = await modelMaker . discoverSingleModel (
287+ this . artifactInfo . dataSource ,
288+ modelInfo . name ,
289+ {
290+ schema : modelInfo . owner ,
291+ disableCamelCase : this . artifactInfo . disableCamelCase ,
292+ } ,
295293 ) ;
294+ if ( this . options . optionalId ) {
295+ // Find id properties (can be multiple ids if using composite key)
296+ const idProperties = Object . values ( modelDefinition . properties ) . filter (
297+ property => property . id ,
298+ ) ;
299+ // Mark as not required
300+ idProperties . forEach ( property => {
301+ property . required = false ;
302+ } ) ;
303+ }
304+ this . artifactInfo . modelDefinitions . push ( modelDefinition ) ;
296305 debug ( `Discovered: ${ modelInfo . name } ` ) ;
297306 }
298-
299- if ( this . options . optionalId ) {
300- // Find id property
301- const idProperty = Object . entries (
302- this . artifactInfo . modelDefinitions [ 0 ] . properties ,
303- ) . find ( x => x [ 1 ] . id === 1 ) [ 0 ] ;
304-
305- // Mark as not required
306- this . artifactInfo . modelDefinitions [ 0 ] . properties [
307- idProperty
308- ] . required = false ;
309- }
310307 }
311308
312309 /**
0 commit comments