Jhipster 用户好友自关系

Jhipster User friend self relationship

我想使用实体 "Friend" 在用户之间创建 "friend" 关系。 我试过了,但没用。

entity Friend {
    status Boolean, 
    modified LocalDate,
    created LocalDate
}

relationship ManyToMany {
    Friend{user(login)} to User,
    User to Friend{user(login)}
}

我该怎么做?

谢谢

您无法在 JDL

中创建与 User 实体的关系

解决方法是创建另一个实体并使用这样的一对一关系

entity Friend {
    status Boolean, 
    modified LocalDate,
    created LocalDate
}

entity UserExtended {
    ...
}

relationship OneToOne {
    UserExtended to User
}

relationship ManyToMany {
    Friend{userExtended(login)} to UserExtended,
    UserExtended to Friend{userExtended(login)}
}

您可能需要考虑直接在生成的代码中创建与 User 的关系。

找到了:

entity UserExtra {
    .....
}
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}
}