nestjs - TypeOrm 存储库在过滤时预加载实体
问题描述
我可以同时调用 preload 方法和过滤实体吗?
例如,这里我想按用户 ID 过滤。
我需要这个的原因是因为我需要确保用户只排除属于他的实体。
async update(id: number, status: TaskStatus, user: User) {
const existingTask = await this.taskRepository.preload({
id: id,
status: status,
});
if (!existingTask) {
throw new NotFoundException(`Task #${id} not found`);
}
return this.taskRepository.save(existingTask);
}
解决方案
推荐阅读
- angular - 从 8 更新到 Angular 11 时出错:无法解析 '/Users/foo/node_modules/request' 中的 'util'
- python - 通过喜欢的帖子的标签检索所有帖子
- postfix-mta - 使用 fail2ban 仅允许特定 ip 连接到邮件帐户
- html - 使用 Microsoft HTML Help Workshop 编译的 chm 文件中的索引为空
- c++ - CLion 运行和 makefile 显示不同的结果
- flutter - Flutter webview 嵌入 URL 和访问令牌并返回 URL
- laravel - 重置 Laravel 速率限制
- java - OptaPlanner 自定义员工排班 - 约束提供程序中的 WeeklyHoursLimit 问题
- ansible - Ansible 从剧本(不是命令行)应用标签
- typescript - 导出 Typescript 类型和类以创建类似 AWS 的开发工具包