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

Vue frontend doesn't detect custom primary key names #23848

Closed rjbgaspar closed 9 months ago

rjbgaspar commented 1 year ago
Overview of the issue

In case we use a primary key with a name other then id the vuejs frontend incorrect generated.

Motivation for or Use Case

n.a.

Reproduce the error

Generate a new project using the JDL provided in "JHipster configuration" section, start the project, go to “Employees” entity and you wont be able to see the id.

Related issues

n.a.

Suggest a Fix

Change the files responsible for generating the vuejs frontened, to mach the appropriated key.

It should target the

JHipster Version(s)

Release 7.9.4 (2023-09-05)

JHipster configuration

The following JDL can be use to demonstrate the issue

JDL definitions
application {
  config {
    baseName primarykeynonid,
    reactive true
    applicationType monolith
    authenticationType jwt
    buildTool maven
    packageName com.jhipster.demo.primarykeynonid,
    clientFramework vue
    prodDatabaseType mssql,
    enableTranslation true
    nativeLanguage pt-pt
    languages [en, pt-pt]
  }
  entities *
}

@dto(mapstruct)
@service(serviceClass)
entity Employee(FUNC1) {
    /**
     * The employee number
     */
    @fieldNameAsDatabaseColumn(NFUNC)
    @Id number String required unique
    /**
     * The employee name
     */
    @fieldNameAsDatabaseColumn(NOME)
    name String required
}

  
Entity configuration(s) entityName.json files generated in the .jhipster directory

n.a.

Browsers and Operating System

n.a.

mshima commented 1 year ago

@rjbgaspar can you contribute with a PR?

rjbgaspar commented 1 year ago

Hi @mshima,

As I mentioned in the other issue, I don't have the project knowledge to do it.

mshima commented 12 months ago

Go to this folder and replace id with <%- primaryKey.name %> (<%- relationship.otherEntity.primaryKey.name %>) for relationships) whenever applicable.

qmonmert commented 9 months ago

@mshima is it normal that the backend sends this for a one-to-one relationship? image

mshima commented 9 months ago

@mshima is it normal that the backend sends this for a one-to-one relationship?

I don't think so.

qmonmert commented 9 months ago

I generate same entities with Vue and Angular and the backend code is different Vue

@Table("player")
@SuppressWarnings("common-java:DuplicatedBlocks")
public class Player implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column("id")
    private Long id;

    @Column("name")
    private String name;

    @Transient
    private Foot foot;

    @Column("foot_id")
    private Long footId;

Angular

@Entity
@Table(name = "player")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@SuppressWarnings("common-java:DuplicatedBlocks")
public class Player implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
    @SequenceGenerator(name = "sequenceGenerator")
    @Column(name = "id")
    private Long id;

    @Column(name = "name")
    private String name;

    @JsonIgnoreProperties(value = { "player" }, allowSetters = true)
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(unique = true)
    private Foot foot;
mshima commented 9 months ago

The first looks reactive, the second looks imperative.

qmonmert commented 9 months ago

ah yes thanks 👍