diff --git a/packages/cli/generators/relation/index.js b/packages/cli/generators/relation/index.js index 1b58cd73751d..c09126136793 100644 --- a/packages/cli/generators/relation/index.js +++ b/packages/cli/generators/relation/index.js @@ -382,6 +382,7 @@ module.exports = class RelationGenerator extends ArtifactGenerator { async promptRegisterInclusionResolver() { // should we let users decide the relation is traversable? + // or promt a warning msg: 'Notice not all models are traversable' return this.prompt([ { type: 'confirm', diff --git a/packages/cli/test/integration/generators/relation.belongs-to.integration.js b/packages/cli/test/integration/generators/relation.belongs-to.integration.js index b161cf4fa3c8..107a68be0f13 100644 --- a/packages/cli/test/integration/generators/relation.belongs-to.integration.js +++ b/packages/cli/test/integration/generators/relation.belongs-to.integration.js @@ -436,11 +436,13 @@ describe('lb4 relation', function() { relationType: 'belongsTo', sourceModel: 'OrderClass', destinationModel: 'CustomerClass', + isInclusionResolverRegistered: false, }, { relationType: 'belongsTo', sourceModel: 'OrderClassType', destinationModel: 'CustomerClassType', + isInclusionResolverRegistered: false, }, ]; @@ -510,7 +512,7 @@ describe('lb4 relation', function() { const singleWordClassConstractor = [ /public readonly customer: BelongsToAccessor;\n/, /constructor\(@inject\('datasources\.db'\) dataSource: DbDataSource, @repository\.getter\('CustomerRepository'\) protected customerRepositoryGetter: Getter,\) \{\n/, - /super\(Order, dataSource\);\n {4}this\.customer = this\.createBelongsToAccessorFor\('customer', customerRepositoryGetter,\);\n {2}\}\n/, + /super\(Order, dataSource\);\n {4}this\.customer = this\.createBelongsToAccessorFor\('customer', customerRepositoryGetter,\);\n/, ]; const multiWordClassConstractor = [ @@ -540,6 +542,29 @@ describe('lb4 relation', function() { assert.fileContent(sourceRepositoryFile, regex); }); }); + + it('registers the inclusion resolver for the relation', async () => { + const singleWordClassConstractor = [ + /this\.registerInclusionResolver\('customer', this\.customer\.inclusionResolver\);\n {2}\}\n/, + ]; + const multiWordClassConstractor = []; + const typeClassConstractor = []; + + const sourceRepositoryFile = path.join( + SANDBOX_PATH, + REPOSITORY_APP_PATH, + repositoryFileName[i], + ); + + const updateConstructorRegEx = [ + singleWordClassConstractor, + multiWordClassConstractor, + typeClassConstractor, + ]; + updateConstructorRegEx[i].forEach(regex => { + assert.fileContent(sourceRepositoryFile, regex); + }); + }); } context('generate model relation for existing property name', () => { diff --git a/packages/cli/test/integration/generators/relation.has-many.integration.js b/packages/cli/test/integration/generators/relation.has-many.integration.js index 11bf0762f679..56f730ad6984 100644 --- a/packages/cli/test/integration/generators/relation.has-many.integration.js +++ b/packages/cli/test/integration/generators/relation.has-many.integration.js @@ -711,11 +711,13 @@ describe('lb4 relation HasMany', function() { relationType: 'hasMany', sourceModel: 'CustomerClass', destinationModel: 'OrderClass', + isInclusionResolverRegistered: false, }, { relationType: 'hasMany', sourceModel: 'CustomerClassType', destinationModel: 'OrderClassType', + isInclusionResolverRegistered: false, }, ]; @@ -778,12 +780,11 @@ describe('lb4 relation HasMany', function() { assert.fileContent(sourceRepositoryFile, regex); }); }); - it('repository has updated constructor', async () => { const singleWordClassConstractor = [ /public readonly orders: HasManyRepositoryFactory;\n/, /constructor\(\@inject\('datasources\.db'\) dataSource: DbDataSource, \@repository\.getter\('OrderRepository'\) protected orderRepositoryGetter: Getter,\) \{\n/, - /super\(Customer, dataSource\);\n {4}this.orders = this.createHasManyRepositoryFactoryFor\('orders', orderRepositoryGetter,\);\n {2}\}\n/, + /super\(Customer, dataSource\);\n {4}this.orders = this.createHasManyRepositoryFactoryFor\('orders', orderRepositoryGetter,\);\n/, ]; const multiWordClassConstractor = [ @@ -812,6 +813,29 @@ describe('lb4 relation HasMany', function() { assert.fileContent(sourceRepositoryFile, regex); }); }); + + it('registers the inclusion resolver for the relation', async () => { + const singleWordClassConstractor = [ + /this\.registerInclusionResolver\('orders', this\.orders\.inclusionResolver\);\n {2}\}\n/, + ]; + const multiWordClassConstractor = []; + const typeClassConstractor = []; + + const sourceRepositoryFile = path.join( + SANDBOX_PATH, + REPOSITORY_APP_PATH, + repositoryFileName[i], + ); + + const updateConstructorRegEx = [ + singleWordClassConstractor, + multiWordClassConstractor, + typeClassConstractor, + ]; + updateConstructorRegEx[i].forEach(regex => { + assert.fileContent(sourceRepositoryFile, regex); + }); + }); } }); });