question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

eager relation load breaks foreign key update

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:7
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Dilukacommented, Nov 12, 2019

@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?

0reactions
cyc1ecommented, Sep 16, 2021

Hi all, I’m having the same issue, whether to wait for a fix?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Eager loading not working with string foreign key - Stack ...
Long answer It seems you tried to configure a one-to-many relationship between Lots and Listings : Every Lot has zero or more Listings...
Read more >
Eager loading not working on many to many relationship
Set up; I have a Programme model with a one to one relation to a User (belongsTo) many to many relation to a...
Read more >
Eager and Lazy Relations - typeorm - GitBook
Eager relations are loaded automatically each time you load entities from the database. For example: import { Entity, PrimaryGeneratedColumn, Column, ...
Read more >
Retrieving Data & Results Sets - 4.x - CakePHP Cookbook
contain define the associations to eager load. ... If the results are missing association entities, make sure the foreign key columns are selected...
Read more >
Sessions / Queries - SQLAlchemy 1.4 Documentation
The answer is that “post_update” is used to break a cycle between two mutually dependent foreign keys, and to have this cycle breaking...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found