Skip to content

fix: do not load lazy relations when building the entity id map - #12985

Merged
alumni merged 1 commit into
typeorm:masterfrom
lazerg:fix/12984-lazy-relation-id-map
Oct 20, 2026
Merged

alumni merged 1 commit into
typeorm:masterfrom
lazerg:fix/12984-lazy-relation-id-map

Conversation

@lazerg

@lazerg lazerg commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Description of change

Fixes #12984

ColumnMetadata.getEntityValueMap() skipped lazy relations by looking for an own getter on the entity, but EntityMetadataBuilder installs the lazy getter on the prototype. For an entity made with new Entity() the check passed, so reading the relation ran the getter and fired an unawaited SELECT on every insert()/save() when a join column is also a primary column. The id map also came back without that column, so insert() returned [undefined] as identifiers. The check now uses relationMetadata.isLazy, so the getter is never touched and the primary value is read from the column itself.

Added a test that inserts and saves such an entity and checks that RelationLoader.load is never called and identifiers holds the code. Both assertions fail on master.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links a relevant issue using a closing keyword:
    Fixes #12984
  • There are new or updated tests validating the change (tests/**.test.ts)
  • Documentation has been updated to reflect this change (docs/docs/**.md) N/A

@github-actions github-actions Bot added the linked-issue PR references an issue label Oct 20, 2026
@pkg-pr-new

pkg-pr-new Bot commented Oct 20, 2026

Copy link
Copy Markdown
  • typeorm-sql-js-example

    npm i https://pkg.pr.new/typeorm@12985
    

commit: d329dfb

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review
  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Grey Divider

Tip of the day
💡 Did you know, you can open the rule or relationship behind a finding in one click

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@Cprakhar
Cprakhar requested a review from alumni October 20, 2026 18:06
@alumni
alumni merged commit 4bd74eb into typeorm:master Oct 20, 2026
50 checks passed
@github-actions github-actions Bot added this to the 2.0.next milestone Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linked-issue PR references an issue

Development

Successfully merging this pull request may close these issues.

insert() / save() start an unawaited lazy-relation query when a join column is also a primary column

3 participants