42seoul/42seoul_

typeorm error : UpdateValuesMissingError: Cannot perform update query because update values are not defined. Call "qb.set(...)" method to specify updated values. / save를 쓰지 말자

mcdn 2022. 9. 17. 21:39
반응형

message repository에 객체를 하나

const msg: Message = await this.messageRepository.create({
        chatRoom: chatRoom,
        msg_content: msgContent,
        date: new Date(),
        userId: userId,
        user: user
});
await this.messageRepository.save(msg);

입력하려고 save 메소드를 사용했다.


하지만

connected -EHVSvlQ_9WlCCKeAAAB
UpdateValuesMissingError: Cannot perform update query because update values are not defined. Call "qb.set(...)" method to specify updated values.
    at UpdateQueryBuilder.createUpdateExpression (/Users/a/ft_transcendence/packages/backend/src/query-builder/UpdateQueryBuilder.ts:679:19)
    at UpdateQueryBuilder.getQuery (/Users/a/ft_transcendence/packages/backend/src/query-builder/UpdateQueryBuilder.ts:53:21)
    at UpdateQueryBuilder.getQueryAndParameters (/Users/a/ft_transcendence/packages/backend/src/query-builder/QueryBuilder.ts:507:28)
    at UpdateQueryBuilder.execute (/Users/a/ft_transcendence/packages/backend/src/query-builder/UpdateQueryBuilder.ts:142:50)
    at updateSubject (/Users/a/ft_transcendence/packages/backend/src/persistence/SubjectExecutor.ts:611:63)
    at Array.map (<anonymous>)
    at SubjectExecutor.executeUpdateOperations (/Users/a/ft_transcendence/packages/backend/src/persistence/SubjectExecutor.ts:663:34)
    at SubjectExecutor.execute (/Users/a/ft_transcendence/packages/backend/src/persistence/SubjectExecutor.ts:148:20)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at EntityPersistExecutor.execute (/Users/a/ft_transcendence/packages/backend/src/persistence/EntityPersistExecutor.ts:194:21)

UpdateValuesMissingError: Cannot perform update query because update values are not defined. Call "qb.set(...)" method to specify updated values.

save 메소드를 쓸 때 이 에러가 났다.


해결

insert 메소드 사용

const msg: Message = await this.messageRepository.create({
        chatRoom: chatRoom,
        msg_content: msgContent,
        date: new Date(),
        userId: userId,
        user: user
      });
await this.messageRepository.insert(msg);



Reference:
https://dev.to/rishit/optimizing-typeorm-tips-from-experience-part-1-dont-use-save-4ke9

TypeORM Tips (Part 1: Don't use save())

Introduction to the series As of January 21st 2022 (source), TypeORM is the 3rd most...

dev.to





반응형