crud: eager relation load breaks foreign key update

When relation set to eager loading, update a foreign key will be failed.

partial entity

export class Book {
  catId:number;

  cat:Cat;
}

When update catId it will load cat to override the update.

https://github.com/nestjsx/crud/blob/d27a1d69238bd35699c590a1eae4a517063c5c59/packages/crud-typeorm/src/typeorm-crud.service.ts#L122-L136

cat in found and only catId in dto The result will be

{
    "catId": "new value",
    "cat": {"id":"old value"}
}

typeorm will use object instead of id

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 7
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

@alexmantaut thanks for the attention. you can see after the refactor this issue seems gone. you can try the next version or just waiting for the next release.

btw, @zMotivat0r When is it released?