Hello I'm generating some Entity with the jhipster generator.
When I generate an entity relationship, I'd like to make the value in that field mandatory but unfortunately, the generator doesn't provide that option.
Is there anyway to inform the generator of this necessity?
(editing the .jhipster/entity_name.json), for example?
Since this commit JHipster supports the required validation on relationships too.
This is an example from a JDL file:
relationship ManyToOne { Certificate{ca(name) required} to CertificateAuthority }
('Certificate' and 'CertificateAuthority' are entities and 'ca' is the field name)
The relevant part from the .jhipster/Certificate.json:
"relationships": [
{
"relationshipType": "many-to-one",
"relationshipValidateRules": "required",
"relationshipName": "ca",
"otherEntityName": "certificateAuthority",
"otherEntityField": "name"
},
The generated Certificate.ca field:
#ManyToOne
#NotNull
private CertificateAuthority ca;
And the generated form has a 'This field is required.' warning at the Ca filed.
No, it would be a new feature.
Feel free to create an issue in our github project and pull requests are always welcome :)
Just for others, here is the issue you opened
Related
I'm trying to create job table have multi-image in JDL
I used to one-to-many relationship but jhipster warnning:
WARNING! otherEntityRelationshipName is missing in .jhipster/Attachment.json for relationship {
"relationshipName": "job",
"otherEntityName": "job",
"relationshipType": "many-to-one",
"otherEntityField": "id",
"otherEntityRelationshipName": "attachment"
}, using attachment as fallback
My job JDL like that:
microservice * with job
entity Job{
name String required
description String
}
entity Attachment{
name String
image ImageBlob
}
relationship OneToMany{
Job{image} to Attachment
}
service * with serviceClass
paginate * with pagination
How can I fix it. please help!
Unidirectional one-to-many relationship is not provided by default in JHipster at the moment.
It should be like this:
relationship OneToMany{
Job{image} to Attachment{job}
}
[JHipster Generator 4.14.4]
i generate an "article" with some relationships with JDL Studio. Relationships in my article.json look like this :
"relationships": [
{
"relationshipType": "one-to-one",
"relationshipName": "adress",
"otherEntityName": "adressDomain",
"otherEntityField": "id",
"ownerSide": true,
"otherEntityRelationshipName": "article"
},
How can i add the required rules to my relationship?
i tried "relationshipValidateRules": "required" but it doesnt works.
My Answer is not to change in the JSON File but to regenerate the *.jh file on JDL-Studio.
Here is how to add the required:
relationship OneToOne {
Article{adress required} to AdressDomain
}
I want to know why Jhipster v5 does not like TextBlob fields validations and what is the substitute (for TextBlob, if we should use other) now?
entity Comment {
creationDate Instant required
commentText TextBlob minbytes(3) maxbytes(5000) required
isOffensive Boolean
}
Hibernate JPA 2 Metamodel does not work with Bean Validation 2 for LOB fields, so LOB validation is disabled
WARNING! Cannot use validation in .jhipster/Comment.json for field {
"fieldName": "commentText",
"fieldType": "byte[]",
"fieldTypeBlobContent": "text",
"fieldValidateRules": [
"minbytes",
"maxbytes",
"required"
],
"fieldValidateRulesMinbytes": 3,
"fieldValidateRulesMaxbytes": 5000
}
This worked fine in version 4.13.
I want to reference a different model(as discribed here: https://loopback.io/doc/en/lb2/Embedded-models-and-relations.html) but the by a nested id:
{
"name" : "person",
...
"relations": {
"cars": {
"type": "referencesMany",
"model": "car",
"foreignKey": "cars.id"
}
}
Person json will actually be something like:
{
...
cars: [{"id": 1, "name": "car1"}, ...]
}
And car model will be the full car details
Do I have to write my own remote method to do this?
Yosh DaafVader,
I've came accross this issue also and took time to find a solution ^^ but actually you just have to play with the parameter options inside your target relation property. The documentation states how the relation should be defined (sure the loopback cli does not include in version 3.x yet the way to use embeds nor references).
In your person model you have to change the foreignKey and to add the following options to be able to only use id to reference cars.
{
"name" : "person",
...
"relations": {
"cars": {
"type": "referencesMany",
"model": "car",
"foreignKey": "",
"options": {
"validate": true,
"forceId": true
}
}
}
Now you will be able to see in the explorer the new routes to add, remove and see the cars that belongs to the target person.
[Edit]
the foreignKey shall be blank, in order to be able to add items properly in the list of cars, or you can test and give some feedbacks about it
The validate option ensures the id exists in your database
forceId option will ensure it accepts only ids as a parameter
[/Edit]
Hope it will help :)
Cheers
I'm experimenting with jHipster.
I want to create a one-to-one relationship from my entity X to the User entity.
This is definition:
"relationships": [
{
"relationshipId": 1,
"relationshipName": "user",
"otherEntityName": "user",
"relationshipType": "one-to-one",
"otherEntityField": "id",
"ownerSide": true,
"otherEntityRelationshipName": "x"
}
]
Unfortunately, as you can see, it also expects changes in the user entity which is actually managed by jHipster. I don't want to change the generated User code.
I have experimented with many-to-one relationships to User. They don't cause problems because there's no otherEntityRelationshipName field.
{
"relationshipId": 1,
"relationshipName": "user",
"otherEntityName": "user",
"relationshipType": "many-to-one",
"otherEntityField": "id"
}
Suggestions are most welcome.
Thanks, Andy
This should work. I just tested it with the latest version 2.22.0 of JHipster.
Are you using the latest version of JHipster? What error do you get?
The "otherEntityRelationshipName": "x"property is actually ignored by the generator when the other relationship entity is User. Though it is still asked by the generator and this is a bug. I have created an issue in github for this, see https://github.com/jhipster/generator-jhipster/issues/2121