jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.41k stars 4.02k forks source link

MongoDB create entities relationship OneToOne fails #22748

Open Murik opened 1 year ago

Murik commented 1 year ago
Overview of the issue

I tried to generate test project via JDL and get error. Create a simple project and try to add 1-to-1 entities according https://www.jhipster.tech/managing-relationships/#embedded-entities-for-couchbase-and-mongodb

Error:

TypeError: C:\Work\jhipster-test\node_modules\generator-jhipster\generators\entity-client\templates\angular\src\main\webapp\app\entities\entity.model.ts.ejs:46
    44|       const { propertyName, relationshipRequired, otherEntity, id, collection, otherEntityField } = relationship;
    45| _%>
 >> 46|   <%= propertyName %>?: Pick<I<%= otherEntity.entityAngularName %>, '<%= otherEntity.primaryKey.name %>'<% if (otherEntity.primaryKey.name !== otherEntityField) { %> | '<%= otherEntityField %>'<% } %>><% if (collection) { %>[]<% } %> | null;
    47| <%_ } _%>
    48| }
    49| <%_ if (primaryKey) { _%>

Cannot read properties of undefined (reading 'name')
    at module.exports.eval ("C:\\Work\\jhipster-test\\node_modules\\generator-jhipster\\generators\\entity-client\\templates\\angular\\src\\main\\webapp\\app\\entities\\entity.model.ts.ejs":98:49)
    at entity.model.ts (C:\Work\jhipster-test\node_modules\ejs\lib\ejs.js:703:17)
    at Object.exports.render (C:\Work\jhipster-test\node_modules\ejs\lib\ejs.js:425:37)
    at exports.render (C:\Work\jhipster-test\node_modules\mem-fs-editor\lib\util.js:97:14)
    at EditionInterface.module.exports._processTpl (C:\Work\jhipster-test\node_modules\mem-fs-editor\lib\actions\copy-tpl.js:10:10)
    at process (C:\Work\jhipster-test\node_modules\mem-fs-editor\lib\actions\copy-tpl.js:29:14)
    at applyProcessingFunc (C:\Work\jhipster-test\node_modules\mem-fs-editor\lib\actions\copy.js:12:18)
    at EditionInterface.exports._copySingle (C:\Work\jhipster-test\node_modules\mem-fs-editor\lib\actions\copy.js:85:16)
    at C:\Work\jhipster-test\node_modules\mem-fs-editor\lib\actions\copy.js:74:10
    at Array.forEach (<anonymous>)
    at EditionInterface.exports.copy (C:\Work\jhipster-test\node_modules\mem-fs-editor\lib\actions\copy.js:68:9)
    at EditionInterface.module.exports.copyTpl (C:\Work\jhipster-test\node_modules\mem-fs-editor\lib\actions\copy-tpl.js:22:8)
    at module.exports.fs.renderTemplate (C:\Work\jhipster-test\node_modules\yeoman-generator\lib\actions\fs.js:215:11)
    at renderTemplate (C:\Work\jhipster-test\node_modules\generator-jhipster\generators\generator-base.js:2557:16)
    at C:\Work\jhipster-test\node_modules\generator-jhipster\generators\generator-base.js:2681:69
    at Array.map (<anonymous>) {
  path: 'C:\\Work\\jhipster-test\\node_modules\\generator-jhipster\\generators\\entity-client\\templates\\angular\\src\\main\\webapp\\app\\entities\\entity.model.ts.ejs'
}
Motivation for or Use Case

Cant create 1-to-1 relationship on MongoBD & angular.

Reproduce the error

Use JDL myApp-jdl.jh

  config {
    applicationType monolith
    authenticationType jwt
    baseName jhiptest
    blueprints []
    buildTool gradle
    cacheProvider ehcache
    clientFramework angularX
    clientPackageManager npm
    clientTheme darkly
    clientThemeVariant dark
    creationTimestamp 1688314770517
    databaseType mongodb
    devDatabaseType mongodb
    dtoSuffix DTO
    enableGradleEnterprise false
    enableHibernateCache false
    enableSwaggerCodegen false
    enableTranslation false
    gradleEnterpriseHost ""
    jhiPrefix jhi
    jhipsterVersion "7.9.3"
    languages [en, fr]
    messageBroker false
    microfrontend false
    microfrontends []
    nativeLanguage ru
    otherModules []
    packageName com.mycompany.myapp
    prodDatabaseType mongodb
    reactive false
    searchEngine false
    serverPort 8080
    skipClient false
    skipUserManagement false
    testFrameworks [cypress]
    websocket false
    withAdminUi true
  }

  entities *
}

entity Country {
  countryName String
}

@embedded
entity Region {
  regionName String
}

@embedded
entity Capital {
  capitalName String
}

relationship OneToOne {
  Country to Capital
}

relationship OneToMany {
  Country to Region
}

service Country with serviceClass

Try to create entities jhipster jdl myApp-jdl.jh

Related issues

15524 #16358 #18017

JHipster Version(s)

7.9.3

JHipster configuration

jhipster info

Welcome to JHipster v7.9.3

Welcome to the JHipster Information Sub-Generator

JHipster Version(s)
jhiptest@0.0.1-SNAPSHOT C:\Work\jhipster-test
`-- generator-jhipster@7.9.3
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
    "applicationIndex": 0,
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "baseName": "jhiptest",
    "blueprints": [],
    "buildTool": "gradle",
    "cacheProvider": "ehcache",
    "clientFramework": "angular",
    "clientPackageManager": "npm",
    "clientTheme": "darkly",
    "clientThemeVariant": "dark",
    "creationTimestamp": 1688314770517,
    "cypressAudit": false,
    "cypressCoverage": true,
    "databaseType": "mongodb",
    "devDatabaseType": "mongodb",
    "devServerPort": 4200,
    "dtoSuffix": "DTO",
    "enableGradleEnterprise": false,
    "enableHibernateCache": false,
    "enableSwaggerCodegen": false,
    "enableTranslation": false,
    "entities": ["Book", "Country", "Region"],
    "entitySuffix": "",
    "gradleEnterpriseHost": "",
    "jhiPrefix": "jhi",
    "jhipsterVersion": "7.9.3",
    "languages": ["en", "fr"],
    "lastLiquibaseTimestamp": 1688339267000,
    "messageBroker": false,
    "microfrontend": false,
    "microfrontends": [],
    "nativeLanguage": "ru",
    "otherModules": [],
    "packageFolder": "com/mycompany/myapp",
    "packageName": "com.mycompany.myapp",
    "pages": [],
    "prodDatabaseType": "mongodb",
    "reactive": false,
    "searchEngine": false,
    "serverPort": "8080",
    "serverSideOptions": [],
    "skipCheckLengthOfIdentifier": false,
    "skipClient": false,
    "skipFakeData": false,
    "skipUserManagement": false,
    "testFrameworks": ["cypress"],
    "websocket": false,
    "withAdminUi": true
}

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions

entity Country {
  countryName String
}

@embedded
entity Region {
  regionName String
}

@embedded
entity Capital {
  capitalName String
}

relationship ManyToOne {
  Country to Capital
}

relationship OneToMany {
  Country to Region
}

service Country with serviceClass

Environment and Tools

openjdk version "17.0.4" 2022-07-19 OpenJDK Runtime Environment Temurin-17.0.4+8 (build 17.0.4+8) OpenJDK 64-Bit Server VM Temurin-17.0.4+8 (build 17.0.4+8, mixed mode, sharing)

git version 2.33.0.windows.2

node: v16.13.0

npm: 8.18.0

Docker version 24.0.2, build cb74dfc

Docker Compose version v2.18.1

No change to package.json was detected. No package manager install will be executed. Congratulations, JHipster execution is complete! Sponsored with ❤️ by @oktadev.

Browsers and Operating System

OS Name Microsoft Windows 10 Pro

github-actions[bot] commented 11 months ago

JHipster has completed the sample check .yo-rc.json: valid Entities JDL: valid Application: Frontend check: skipped Backend check: skipped E2E check: skipped

This check uses jhipster info output from the issue description to generate the sample. Bug report that does not contain this information will be marked as invalid.

schndra commented 9 months ago

Any update on this ? I'm receiving the same error in JHipster version 7.9.4

Murik commented 4 months ago

the same issue on JHipster 8.2.1

mshima commented 3 months ago

This is more than a simple bug. Is a concept bug.

We have a few tasks:

@DanielFran @mraible