Why My jdl file is generating domains with error in code? - jhipster

Hi I m using JHipster and doing some training in the jdl,
so while I generated a entity model from my jdl I got some code scaffolding errors, is this due to an error in my JDL or it is a issue in JHipster generator
entity Club{
federation String,
nomClub String,
dateFondation LocalDate
}
entity Boxeur {
nom String,
prenom String,
dateNaissance LocalDate,
lieuNaissance String,
dateInscription LocalDate
}
entity Entraineur{
nom String,
prenom String,
dateNaissance LocalDate,
lieuNaissance String,
president Boolean
}
enum LieuSeance {
SALLE,
STADE,
MONTAGNE,
AUTRE
}
entity TypeSeance{
typeSeance TypeSeance0
}
enum TypeSeance0 {
COMPETITION,
SPARRING,
ENDURANCE,
STREATCHING,
TECHNIQUE,
PHYSIQUE,
ENTRETIEN,
AUTRE
}
entity Seance{
titre String,
detail String,
dateSeance LocalDate,
lieu LieuSeance
}
entity Payement{
montant Long,
datePayement LocalDate
}
relationship OneToMany{
Entraineur{seances(titre)} to Seance{entreneur(nom)},
Boxeur{versement} to Payement,
TypeSeance to Seance
}
relationship OneToOne{
Club{president(nom)} to Entraineur
}
relationship ManyToMany{
Seance{participants(nom)} to Boxeur{assistes(titre)}
}
paginate all with pagination
dto * with mapstruct
service all with serviceImpl
the error is in the Seance.Java where add and remove participants got errors in scafolding like in the picture below
Did I make a mistake in my JDL file so I got this scafolding errors
Thanks you
I created an issue in JHipster

Issue Corrected in new release
for more info visit github issue tracker

Related

How to use Schema.virtual in typescript?

I was using schema.virtual property in js but now i want to use it with tyescript and getting error.
this is my code
UserSchema.virtual('fullname').get(function () {
return `${this.firstName} ${this.lastName}`
});
I am facing this error
this' implicitly has type 'any' because it does not have a type annotation.
There are a few solutions to work around this specific problem, for example declaring an interface for typing this, but in my experience this will create other issues (one being that doc.fullname will cause an error because TS isn't smart enough to know fullname has been added as a virtual).
The easiest way to solve this is to make virtuals part of the Schema declaration:
const UserSchema = new mongoose.Schema({
firstName : String,
lastName : String,
...
}, {
virtuals : {
fullname : {
get() {
return `${this.firstName} ${this.lastName}`;
}
}
}
});

How to use aws amplify searchable to search multiple key of model?

I am using amplify graphql api. Where I have an Item model with different attributes.
I am trying to create an autocomplete or autosuggest api with user-added input.
type Item #model
#searchable
{
id: ID!
name: String!
description: String
category: String
fullAddress: String!
street: String
area: String
district: String
city: String
state: String!
zip: Int!
Right now I aam querying it like
query SearchEvent {
searchEvents(filter:{
name: {
ne: $query
}
}) {
items {
id
name
}
}
}
But this gives me only full word match to a particular key, like this example is match of name.
How do I query to get a response of any match or suggestions from any key of the item object?
For example, if my item name is Laptop and api query is la it should return the laptop item and other matching items name.
Likewise, if api query is ala it should return the Alabama, Alaska names including the item name matching with ala with a limit to 10 let's say.
Anyway is this possible? Any lead will eb helpful.

Jhipster - setting up many to many relationship for user-entities

Want to create entity called Friendship and want to leverage the User entity that's part of Jhipster,
But I keep getting this invalid-relationship error (full error below).
User has friends (user entities) and vice-versa
entity UserExtended {
}
entity Friend{
status Boolean,
modified LocalDate,
created LocalDate
}
relationship OneToOne {
UserExtended{user(login)} to User
}
relationship OneToMany {
UserExtended{friends} to Friend{user}
}
relationship ManyToOne {
UserExtended{friend} to UserExtended{users}
}
entity Post {
owner UserExtended,
content String,
dateCreated LocalDate
}
entity Like {
likedBy UserExtended,
post Post,
dateCreated LocalDate
}
entity Comment {
postedBy UserExtended,
post Post,
dateCreated LocalDate
}
relationship OneToMany {
UserExtended{post} to Post{user}
}
relationship OneToMany {
Like{post} to Post{like}
}
relationship OneToMany {
Comment{post} to Post{comment}
}
Error:
Error: Can't add invalid relationship. Error: In the Many-to-One relationship from UserExtended to UserExtended, only unidirectionality is supported, you should either create a bidirectional One-to-Many relationship or remove the injected field in the destination entity instead.
Error while parsing applications and entities from the JDL Error: Can't add invalid relationship. Error: In the Many-to-One relationship from UserExtended to UserExtended, only unidirectionality is supported, you should either create a bidirectional One-to-Many relationship or remove the injected field in the destination entity instead.
Error: Can't add invalid relationship. Error: In the Many-to-One relationship from UserExtended to UserExtended, only unidirectionality is supported, you should either create a bidirectional One-to-Many relationship or remove the injected field in the destination entity instead.
You have several problems in your JDL. For example, you should not mix relationships and entities like this:
entity Post {
owner UserExtended, // <-- This is a problem
content String,
dateCreated LocalDate
}
If I have understood your requirements correctly you want to design a kind of blog and let users form friendships. JDL will not let you add relationships starting from the core entity User so you have created a UserExtended and will possibly store some extra information there.
Remember that you can design multiple relationships inside one relationship block. In fact I think it is a good practice, makes the whole JDL a bit more readable.
This should do what you need:
entity UserExtended
entity Friend {
status Boolean
modified LocalDate
created LocalDate
}
entity Post {
content String
dateCreated LocalDate
}
entity Like {
dateCreated LocalDate
}
entity Comment {
dateCreated LocalDate
}
relationship OneToOne {
UserExtended{user(login)} to User
}
relationship ManyToOne {
Post{owner} to UserExtended
Comment{postedBy} to UserExtended
Like{likedBy} to UserExtended
Friend{user} to UserExtended
}
relationship OneToMany {
UserExtended{friends} to Friend
Post{likes} to Like
Post{comments} to Comment
}
The only tricky part here is the many-to-many between two users in a relationship called Friend. You need to store some extra information about the friendship (status, modified, created) so we had to split this many-to-many into a one-to-many plus a many-to-one using the Friend entity as a join table with extra fields.
I did not change your naming scheme, which could probably be improved.
Remember to check the official documentation and optionally use JHipster Online for JDL storage and validation.
Try renaming
relationship OneToOne {
UserExtended{user(login)} to User
}
to
relationship OneToOne {
UserExtended{somethingElse(login)} to User
}

hipster - importing JDL

I'm new to jhipster. so I'm sorry if the answer is obvious.
I'm trying to import my JDL with the command :
import-jdl ~/Downloads/jhipster-jdl.jh --debug
my JDL:
entity Package{
origin String,
destination String,
amORpm String,
department Integer,
weight Long,
barcode Long
}
entity Supplier {
regionName String required
}
entity Mission{
dueDate Instant required
}
entity Seller {
streetAddress String,
postalCode String,
city String,
stateProvince String,
phoneNumber String
}
entity WareHouse{
regionName String
}
entity Timer {
firstName String,
lastName String,
email String,
phoneNumber String,
hiringDate Instant required
}
entity GraphDataWeight {
effort Long
}
relationship OneToOne{
Mission {missionId} to Package
}
relationship OneToMany {
Supplier {packageId} to Package
Seller {sellerId} to Mission
Timer {timerId} to Mission
WareHouse {timerId} to Timer
GraphDataWeight {sellerId1} to Seller
GraphDataWeight {sellerId2} to Seller
}
paginate all with infinite-scroll
paginate all with pagination
dto * with mapstruct
Set service options to all except few
service all with serviceImpl
Set an angular suffix
angularSuffix * with mySuffix
the error I get:
The JDL is being parsed.
DEBUG! Error:
Error: The entity must be valid in order to be added.
Errors: The entity name cannot be a reserved keyword
tried all options that I found to fix it but I get the same error
at the begging I had an enum but I changed it just to get it to work. but I still get this error
I don't see any reserved words that I know of
thanks in advance for ur time
You cannot call an entity Package since it is a reserved keyword.
You also need to remove or comment out Set service options to all except few and Set an angular suffix to make it work.

How to get data from MySql relation table in Prisma

In datamodel.graphql
type Ride {
rideId: String
productId: String
passenger: Passenger
origin: Origin
destination: Destination
dateTime: DateTime
feedback: String
}
type Passenger {
id: ID! #unique
firstName: String
lastName: String
}
type Destination {
# The unique ID of the destination.
id: ID! #unique
latitude: Float
longitude: Float
address: String
}
type Origin {
id: ID! #unique
latitude: Float
longitude: Float
address: String
}
type Report {
productId: String
passenger: Passenger
description: String
}
I deployed this data model and generates a MySql Db, auto queries, mutations with this.
It creates a "Ride", "Passenger", "Report" and "Origin" table in MySql. But it didn't create any column for passenger, origin, destination in "Ride" table.
It separates creates a relation table for this like _PassengerToRide, _OriginToRide, and _DestinationToRide.
Lack of relation establishment in "Ride" table, I couldn't get the details from Passenger, Origin and Destination tables when I query "rides()". Is this the correct way to define the datamodel.graphql. (edited)
Based on your description, this query should "just work":
query {
rides {
feedback
passenger {
id
}
origin {
id
}
destination {
id
}
}
}
Prisma uses the relation table approach you mentioned to keep track if relations between two nodes, for example table _OriginToRide relates to relation #relation(name: "OriginToRide") from your datamodel.
You don't have to change anything on the SQL level to connect the relations afterwards.
Note: The above applies to Prisma database connectors with activated migrations. If your connector doesn't do migrations, different approaches to represent relations are supported. The respective datamodel to support this can be generated by introspecting your existing database schema.

Resources