代码之家  ›  专栏  ›  技术社区  ›  Mike

如何关联Jhipster JDL中的两个实体?

  •  0
  • Mike  · 技术社区  · 6 年前

    假设您有一个Jhipster应用程序,它有一个配置文件,需要注册哪些配置文件遵循其他配置文件,并具有两个属性:一个用于跟随的用户(用户配置文件),另一个用于跟随的用户(跟随的配置文件)。类似于:

    entity Profile {
        creationDate Instant required
    }
    
    entity Follows {
      creationDate Instant
    }
    
    relationship OneToMany {
        Profile{follows(user)} to Follows{profile(id)}
        Profile{follows(followed)} to Follows{profile(id)}
    }
    

    问题在于如下。java有两个完全相同的atributes,即使后面的名称不同(user)(&以下(以下):

    @ManyToOne
    private Profile profile;
    

    。。。而不是

    @ManyToOne
    private Profile user;
    
    @ManyToOne
    private Profile followed;
    

    谢谢

    3 回复  |  直到 6 年前
        1
  •  2
  •   Jon Ruddell    6 年前

    您对这两个关系使用相同的关系名称,但每个关系名称需要不同,否则字段会冲突。

    relationship (OneToMany | ManyToOne | OneToOne | ManyToMany) {
      <from entity>[{<relationship name>[(<display field>)]}] to <to entity>[{<relationship name>[(<display field>)]}]
    }
    

    JDL Relationship Declaration Docs

    在JDL示例中,我将显示字段从 user / followed id 因为实体上不存在这些字段。重要的变化是关系名称是唯一的。

    relationship OneToMany {
        Profile{followed(id)} to Follows{followed(id)}
        Profile{following(id)} to Follows{following(id)}
    }
    
        2
  •  0
  •   RaduGheorghescu    6 年前
    entity Profile {
        creationDate Instant required
    }
    
    entity Follows {
      creationDate Instant
    }
    
    relationship ManyToOne{
        Follows{user} to Profile
        Follows{followed} to Profile
    }
    
        3
  •  0
  •   Inês Gomes    6 年前

    Supposing you want relation between Rooms and Patient

    您可以拥有这些实体

    entity NmsPatient {
    photo ImageBlob
    }
    
    entity NmsRoom {
    code String required,
    name String required
    }
    
    entity NmsPatientRoom {
        begin ZonedDateTime,
        end ZonedDateTime
    }
    

    然后

    relationship ManyToOne {
     NmsPatientRoom{patient} to NmsPatient,
     NmsPatientRoom{room} to NmsRoom
    }