[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
}
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}
}
I'm using jhipster-generator 4.14.5 and im trying to generate an Entity with a field Persons. But Persons is a List of String List<String> Persons.
How can i achieve it in JHipster. I tried to generate a simple field as String, then i changed the POJO like this :
#ElementCollection
#Column(name="persons")
List<String> persons;
The domain.json containing the whole table remain not touched.
I tried to run the application, after running liquibase:diff, without success. How can i fix it?
Use the generator entity to create a relationship :
Create an entity Person (maybe with only the "name", but more fields will soon be needed. Like "active", some dates ...)
.jhipster/[YourEntity].json should contain :
"fields": [
{
"fieldName": "xxx",
"fieldType": "Integer"
}
],
"relationships": [
{
"relationshipName": "person",
"otherEntityName": "person",
"relationshipType": "one-to-many",
"relationshipValidateRules": [
"required"
],
"otherEntityField": "name"
}
],
don't forget to commit before using the generator. Maybe you will need multiple executions to get it right.
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
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