我有许多链接的标签和文章实体。 如果我知道商品编号,如何找到标签?
@Entity("articles")
class ArticleEntity {
@ManyToMany(() => TagEntity, tag => tag.articles)
@JoinTable()
tags: TagEntity[];
}
@Entity("tags")
class TagEntity {
@ManyToMany(() => ArticleEntity, article => article.tags)
articles: ArticleEntity[];
}
const articleId = 1;
this.tagRepo.find({ where: { articles: { id: articleId } } }); // ??
答案 0 :(得分:0)
paid week
total invoice 1 2 3 4 5 6 7 8
week 1 800k 10% 5% 20%
week 2 600k 11% 20%
week 3 1m 15%
中指定关联性FindOptions
const articleId = 1;
const article = await connection.getRepository(ArticleEntity)
.findOne(articleId, {relations: ["tags"]});
console.log(article.tags); // contains all tags related to the article.id = 1
可以加入他们QueryBuilder