Typeorm:自引用关系表设计

时间:2020-01-29 14:12:33

标签: node.js database typeorm

  1. 用户通过匹配实体具有0 .. *个匹配的用户
  2. 匹配有0 .. *条消息

因此,我创建了这些实体,但是在创建/查询数据时遇到了一些困难。那么,如何用以下信息设计一个好的数据库?

用户实体

  @Field()
  @Column()
  name: string;

  @Field()
  @Column()
  email: string;

匹配实体

  @Field(()=> Int, {nullable: true})
  @Column()
  userId: number;

  @Field(()=> Int, {nullable: true})
  @Column()
  matchedUserId: number;


  @Field(() => [Message], {nullable: true})
  @OneToMany(() => Message, message => message.match)
  messages: Message[]

0 个答案:

没有答案
相关问题