【问题标题】:typeorm return limited rows with relationstypeorm 返回具有关系的有限行
【发布时间】:2021-01-11 11:54:56
【问题描述】:

我需要返回有限行的关系数据,我已经看到使用查询生成器的解决方案我们如何使用标准 typeorm 事件来实现相同的目标?

return await Product.find({ relations: ['productSizes', 'productColors'] }); 

【问题讨论】:

  • 您的意思是从productSizesproductColors limited 获得有限的行数?
  • 不,限制主要关系的行,即产品

标签: typeorm


【解决方案1】:

为您的产品实体做限制,您只需要添加take:numberTolimit

return await Product.find({ relations: ['productSizes', 'productColors'],take:10 });

Ps :您可以使用skip - 实体应取位置的偏移量。

【讨论】:

  • 太好了,不知道为什么文档中没有提到这一点,继续努力!
  • 你可以在这里找到它find-options
猜你喜欢
  • 2021-08-09
  • 2021-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多