Jhipster用户朋友自我关系

时间:2018-12-02 16:02:20

标签: jhipster

我想使用实体“朋友”在用户之间创建“朋友”关系。 我试过了,但是不行。

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

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

我该怎么做?

谢谢

2 个答案:

答案 0 :(得分:3)

您无法与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建立关系。

答案 1 :(得分:0)

找到了:

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}
}