javascript - Typeorm 一对多关系和树
问题描述
您好,我有Post实体:
@Entity()
export class Post extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@Column()
title: string;
@OneToMany(() => Comment, (comment) => comment.post)
comments: Comment[];
}
和评论实体:
@Entity()
@Tree('closure-table')
export class Comment extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column({ type: 'text' })
body: string;
@TreeParent()
parent: Comment;
@TreeChildren()
children: Comment[];
@ManyToOne(() => Post, (post) => post.comments)
post: Post;
}
帖子与评论有一对多关系,评论有树关系。
我想获取具有树关系的 id 为 1 的帖子的评论,但不知道该怎么做!
我可以以树的方式获取评论,但无法以树的方式获取帖子评论。
解决方案
推荐阅读
- java - 为测试设置默认 Content-Type
- amazon-web-services - 通过 ansible 安装 aws-iam-authenticator
- python - 我可以运行 Google Colab(免费版)脚本然后关闭我的计算机吗?
- javascript - 从字符串正则表达式获取内联样式顶部
- azure-devops - 确保团队在自己的区域创建项目
- unix - 用于 grep 一行中特定字符串的 Unix 脚本
- r - 从R中的pdf文件中抓取数据
- html - 引导/垂直居中文本
- javascript - 如何使用 Jest 在 ES6 类方法中测试对 redux 存储的调度?
- javascript - 使用 React 在单击时更改正文元素的背景颜色?