Skip to content

fix: resolve relation values for join columns inside embedded entities - #12726

Merged
michaelbromley merged 3 commits into
typeorm:masterfrom
michaelbromley:fix/12725-embedded-relation-id-column
Jul 22, 2026
Merged

michaelbromley merged 3 commits into
typeorm:masterfrom
michaelbromley:fix/12725-embedded-relation-id-column

Conversation

@michaelbromley

@michaelbromley michaelbromley commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

Description of change

Fixes #12725

When a column inside an embedded entity is both an explicitly declared column and the join column of a relation (the relation id column pattern, e.g. @Column() avatarId alongside @ManyToOne() avatar), assigning a relation object to the embedded property was silently not persisted — on both INSERT and UPDATE. The same pattern on a non-embedded property works correctly.

The cause: the embedded branch of ColumnMetadata.getEntityValue() called this.relationMetadata.getEntityValue(embeddedObject), passing the already-extracted embedded object. RelationMetadata.getEntityValue() expects the full entity and performs the embedded-path traversal itself via parentPropertyNames, so the relation value always resolved to undefined and the code fell back to the explicit column property, which relation-object assignments do not populate. The value resolved to undefined and the persistence layer skipped the column.

The fix passes the full entity, mirroring what the non-embedded branch of the same method already does.

Verified with new regression tests in test/functional/embedded/embedded-relation-id-column/:

  • sanity check that the explicit id column is merged with the relation's join column (single column metadata)
  • control test: the same pattern on a top-level property (passed before and after)
  • relation object assignment inside an embedded, on insert and on update (failed before, passes now)

The full test suite passes against better-sqlite3 with no regressions.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links a relevant issue using a closing keyword:
    Fixes #12725
  • 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 — bug fix, no documented behavior change

@pkg-pr-new

pkg-pr-new Bot commented Jul 21, 2026 •

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

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

commit: c6f0e89

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

qodo-free-for-open-source-projects Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Test added under github-issues ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
This fix adds new regression coverage only under test/github-issues/12725/, instead of placing it
in the functional test suite. This makes the test organization less maintainable and violates the
preference for functional tests for issue fixes.
Code

test/github-issues/12725/issue-12725.test.ts[R1-12]

+import "reflect-metadata"
+import type { DataSource } from "../../../src"
+import {
+    closeTestingConnections,
+    createTestingConnections,
+    reloadTestingDatabases,
+} from "../../utils/test-utils"
+import { Avatar } from "./entity/Avatar"
+import { Profile, User } from "./entity/User"
+import { expect } from "chai"
+
+describe("github issues > #12725 relation assigned inside an embedded entity is not persisted when the join column is shared with an explicit column", () => {
Evidence
PR Compliance ID 3 requires issue fixes to add/update tests in test/functional rather than only
adding per-issue tests under test/github-issues. The added test file is located under
test/github-issues/12725/ and is explicitly labeled as a GitHub issue test, with no indication in
the change that functional placement is not feasible.

Rule 3: Prefer functional tests over per-issue tests
test/github-issues/12725/issue-12725.test.ts[1-12]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The PR adds per-issue tests under `test/github-issues/12725/`, but the compliance checklist requires issue fixes to live in the functional test suite when possible.
## Issue Context
The new test file is explicitly labeled as a GitHub issue test (`describe("github issues > #12725 ...")`) and resides under `test/github-issues/`, with no reason stated in code/comments for why it cannot be placed under `test/functional`.
## Fix Focus Areas
- test/github-issues/12725/issue-12725.test.ts[1-106]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Qodo Logo

@michaelbromley
michaelbromley merged commit 008f5c6 into typeorm:master Jul 22, 2026
46 checks passed
@github-actions github-actions Bot added this to the 2.0.next milestone Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Relation object assigned inside an embedded entity is silently not persisted when the join column is shared with an explicit column

3 participants