如何使实体关系成为必需的

How to make an entity relationship required

您好,我正在使用 jhipster 生成器生成一些实体。

当我生成实体关系时,我想将该字段中的值设为必填,但不幸的是,生成器不提供该选项。

有没有办法通知生成器这种必要性? (编辑.jhipster/entity_name.json),例如?

不,这将是一项新功能。 欢迎随时在我们的 github 项目中创建问题,我们随时欢迎拉取请求:)

只是为了其他人,这里是the issue you opened

因为 this commit JHipster 也支持必需的 关系验证。

这是 JDL 文件中的示例:

relationship ManyToOne { Certificate{ca(name) required} to CertificateAuthority }

('Certificate'和'CertificateAuthority'是实体,'ca'是字段名)

相关部分来自.jhipster/Certificate.json:

"relationships": [ { "relationshipType": "many-to-one", "relationshipValidateRules": "required", "relationshipName": "ca", "otherEntityName": "certificateAuthority", "otherEntityField": "name" },

生成的Certificate.ca字段:

@ManyToOne @NotNull private CertificateAuthority ca;

并且生成的表单在 Ca 字段中有一个 'This field is required.' 警告。