【问题标题】:Error when trying to update or get Entity with OneToOne relation尝试更新或获取具有 OneToOne 关系的实体时出错
【发布时间】:2021-04-07 08:03:56
【问题描述】:

我正在尝试发出GET 请求。我有一个主要的Article 实体和一个ArticleContent 实体。我不知道连接有什么问题。当我试图取回之前创建的实体时,ArticleContent 列是 null(它应该是 ArticleContent 的 id)。

这是Article

@Entity('article')
export class Article extends DefaultEntity {

  @Column({ type: 'integer', default: 0 })
  numberOfViews: number;

  @Column({
    type: 'enum',
    enum: ArticleType,
    default: ArticleType.BLOG,
  })
  type: ArticleType;

  @OneToOne(() => ArticleContent, { cascade: true, eager: true })
  @JoinColumn()
  content: ArticleContent;
}

ArticleContent:

@Entity({ name: 'article_content' })
export class ArticleContent extends DefaultEntity {
  @Column({ type: 'text' })
  title: string;

  @Column({ type: 'text', nullable: true })
  summary: string;

  @Column({ type: 'text', nullable: true })
  description: string;
}

我如何提出POST 请求:

{
  "numberOfViews" : "13", 
  "type:" : "NEWS",
  "content" : [{
      "title" : "TEST"
  }]
}

GET 请求后我看到的内容:

"content": null

【问题讨论】:

    标签: typescript postgresql typeorm


    【解决方案1】:

    我认为问题在于content 的类型是ArticleContent,这是一个obejct,但您在@ 中将一个array 传递给它987654323@请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-14
      • 1970-01-01
      • 1970-01-01
      • 2017-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多