Friendship이라는 엔티티를 만들고 Jhipster의 일부인 User 엔티티를 활용하고 싶지만이 잘못된 관계 오류가 계속 발생합니다 (아래 전체 오류).
사용자는 친구 (사용자 엔티티)가 있고 그 반대도 마찬가지입니다.
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: 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.
JDL에 몇 가지 문제가 있습니다. 예를 들어 다음과 같은 관계와 엔터티를 혼합해서는 안됩니다.
entity Post {
owner UserExtended, // <-- This is a problem
content String,
dateCreated LocalDate
}
요구 사항을 올바르게 이해했다면 일종의 블로그를 디자인하고 사용자가 우정을 쌓을 수 있도록하고 싶습니다. JDL은 핵심 엔터티에서 시작하는 관계를 추가하도록 허용하지 않으므로을 User
생성하고 UserExtended
추가 정보를 저장할 수 있습니다.
하나의 relationship
블록 안에 여러 관계를 설계 할 수 있습니다 . 사실 저는 이것이 좋은 습관이라고 생각하며 전체 JDL을 좀 더 읽기 쉽게 만듭니다.
필요한 작업을 수행해야합니다.
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
}
여기서 까다로운 부분은 many-to-many
라는 관계에서 두 사용자 사이의 관계 Friend
입니다. 우정에 대한 추가 정보 (상태, 수정, 생성)를 저장해야하므로 엔터티를 추가 필드가있는 조인 테이블로 사용하여 many-to-many
이를 one-to-many
플러스 로 분할해야 했습니다 .many-to-one
Friend
개선 될 수있는 이름 지정 체계를 변경하지 않았습니다.
공식 문서 를 확인 하고 선택적 으로 JDL 저장 및 검증을 위해 JHipster Online 을 사용해야 합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다