TypeORM: update item and return it

后端 未结 4 1444
感情败类
感情败类 2021-02-18 14:47

As far as I know, it\'s a best practice to return an item after it has been updated. TypeORM\'s updateById returns void, not the updated item though.

4条回答
  •  甜味超标
    2021-02-18 15:02

    To expand on sandrooco's answer, this is what I do:

    const property = await this.propertyRepository.findOne({
      where: { id }
    });
    
    return this.propertyRepository.save({
      ...property, // existing fields
      ...updatePropertyDto // updated fields
    });
    

提交回复
热议问题