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.54k stars 4.02k forks source link

List screens don't show username in relationship #24033

Closed mraible closed 12 months ago

mraible commented 12 months ago
Overview of the issue

If I create an app with the following JDL and JHipster 8.0.0 RC1, it fails to display the user in the list screens. If I edit the item, the user is assigned correctly, and I can change it.

application {
  config {
    applicationType monolith,
    baseName HealthPoints
    packageName com.okta.developer,
    authenticationType jwt,
    prodDatabaseType postgresql,
    buildTool gradle,
    testFrameworks [cypress],
    clientFramework react,
    enableTranslation true,
    nativeLanguage en,
    languages [en, es]
  }
  entities Points, BloodPressure, Weight, Preferences
}

// JDL definition for application 'TwentyOnePoints' generated with command 'jhipster export-jdl'

entity BloodPressure {
  timestamp ZonedDateTime required
  systolic Integer required
  diastolic Integer required
}
entity Weight {
  timestamp ZonedDateTime required
  weight Double required
}
entity Points {
  date LocalDate required
  exercise Integer
  meals Integer
  alcohol Integer
  notes String maxlength(140)
}
entity Preferences {
  weeklyGoal Integer required min(10) max(21)
  weightUnits Units required
}

enum Units {
  KG,
  LB
}

relationship OneToOne {
  Preferences{user(login)} to User with builtInEntity
}
relationship ManyToOne {
  BloodPressure{user(login)} to User with builtInEntity
  Weight{user(login)} to User with builtInEntity
  Points{user(login)} to User with builtInEntity
}

paginate BloodPressure, Weight with infinite-scroll
paginate Points with pagination
Motivation for or Use Case

If there is a relationship with a user, it should be displayed in the list screen.

Reproduce the error

Create a new app with the JDL above and add a couple of records. No user is displayed on the list screen, but one is selected in the edit screen.

list edit
JHipster Version(s)
health-points@0.0.1-SNAPSHOT /Users/mraible/Downloads/21p
└── generator-jhipster@8.0.0-rc.1
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "applicationIndex": 0,
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "baseName": "HealthPoints",
    "buildTool": "gradle",
    "clientFramework": "react",
    "creationTimestamp": 1698472313459,
    "devServerPort": 9060,
    "enableTranslation": true,
    "entities": [
      "Points",
      "BloodPressure",
      "Weight",
      "Preferences"
    ],
    "herokuAppName": "windypoop",
    "herokuDeployType": "git",
    "herokuJavaVersion": "21",
    "jhipsterVersion": "8.0.0-rc.1",
    "languages": [
      "en",
      "es"
    ],
    "lastLiquibaseTimestamp": 1698472528000,
    "nativeLanguage": "en",
    "packageFolder": "com/okta/developer",
    "packageName": "com.okta.developer",
    "prodDatabaseType": "postgresql",
    "testFrameworks": [
      "cypress"
    ]
  }
}
Environment and Tools

openjdk version "21" 2023-09-19 OpenJDK Runtime Environment GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15) OpenJDK 64-Bit Server VM GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15, mixed mode, sharing)

git version 2.39.3 (Apple Git-145)

node: v18.18.2 npm: 9.8.1

Docker version 24.0.6, build ed223bc

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Points {
  date LocalDate required
  exercise Integer
  meals Integer
  alcohol Integer
  notes String maxlength(140)
}
entity BloodPressure {
  timestamp ZonedDateTime required
  systolic Integer required
  diastolic Integer required
}
entity Weight {
  timestamp ZonedDateTime required
  weight Double required
}
entity Preferences {
  weeklyGoal Integer required min(10) max(21)
  weightUnits Units required
}
enum Units {
  KG,
  LB
}

relationship OneToOne {
  Preferences{user(login)} to User with builtInEntity
}
relationship ManyToOne {
  Points{user(login)} to User with builtInEntity
  BloodPressure{user(login)} to User with builtInEntity
  Weight{user(login)} to User with builtInEntity
}

paginate Points with pagination
paginate BloodPressure, Weight with infinite-scroll
search Points, BloodPressure, Weight, Preferences with no

mshima commented 12 months ago

Duplicated of https://github.com/jhipster/generator-jhipster/issues/23917?

mraible commented 12 months ago

@mshima I tried both of these options in JDL, and neither one results in the user showing up in the list:

@RelationshipEagerLoad Points{user(login)} to User with builtInEntity
Points{user(login)} to @RelationshipEagerLoad User with builtInEntity
hide212131 commented 12 months ago

@mraible @mshima

In the entity list view, the backend returns related entities with only an id field, but the frontend expects a different field.

Response JSON and relevant code are as follows:

Response:

[ 
{
  "id" : 1,
  "date" : "2023-10-29",
  "exercise" : 6654,
  "meals" : 10241,
  "alcohol" : 9875,
  "notes" : "tightly",
  "user" : {
    "id" : 1
  }
},
]

employee.tsx:

<td>{points.user ? points.user.login : ''}</td> 

I believe it should be points.user.id, regardless of the JDL's {user(login)}. (My understanding is that the JDL's \<display field> only affects the details and update views.)

mshima commented 12 months ago

Display field is supposed to be eager loaded due to this condition. https://github.com/jhipster/generator-jhipster/blob/20b31a71ed2f413b6e28fc0c4e73daefb1e46d08/generators/base-application/support/prepare-entity.mts#L629

And eager load apis should be generated: https://github.com/jhipster/generator-jhipster/blob/3cdd7445bf31c131f6fd89686536f722c6ee76af/generators/server/templates/src/main/java/_package_/_entityPackage_/repository/_entityClass_Repository.java.ejs#L81

mshima commented 12 months ago

I've generated the project, react and probably vue does not eager load the list by default.