Skip to content

fix: enhance delegate model interaction with afterEntityMutation plugin support in child updates#2369

Merged
ymc9 merged 4 commits intozenstackhq:devfrom
genu:fix/update-delegate-with-plugin-hooks
Feb 22, 2026
Merged

fix: enhance delegate model interaction with afterEntityMutation plugin support in child updates#2369
ymc9 merged 4 commits intozenstackhq:devfrom
genu:fix/update-delegate-with-plugin-hooks

Conversation

@genu
Copy link
Contributor

@genu genu commented Feb 11, 2026

Fixes #2367

Summary by CodeRabbit

  • Bug Fixes

    • Child record updates for inherited models now use strict ID-based filters to prevent incorrect update scopes and improve reliability.
    • Narrower update filters reduce risk of accidental multi-record updates when base-model data is involved.
  • Tests

    • Added end-to-end tests covering delegate model interactions and entity mutation hooks to validate create/update flows and field propagation.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 11, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

The PR narrows the child-update filter in delegate updates to use only base-model ID fields derived from the base update result and adds an end-to-end test that exercises delegate child-model updates when an afterEntityMutation hook is present.

Changes

Cohort / File(s) Summary
Core fix
packages/orm/src/client/crud/operations/base.ts
Adjusts child UPDATE WHERE composition for delegate scenarios: when a base update returns a baseEntity, replace the full object with ID-only values via getIdValues(this.schema, modelDef.baseModel!, baseUpdateResult.baseEntity), ensuring child updates use an ID-based filter.
E2E tests
tests/e2e/orm/plugin-infra/entity-mutation-hooks.test.ts
Adds a test suite exercising delegate model updates with an afterEntityMutation hook: creates a base/child delegate, performs an update touching base and child fields, and asserts correct updated values. The test block appears duplicated in the diff.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibbled code and found the clue,
Swapped full beans for ID stew.
Hooks may watch, but now they see,
Child updates hop home safely. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing delegate model interaction by enhancing support for the afterEntityMutation plugin hook in child updates.
Linked Issues check ✅ Passed The changes address the linked issue #2367 by modifying the base update filter to use only ID values instead of the entire base entity, ensuring child updates work correctly when afterEntityMutation hooks are present.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the delegate model interaction issue: the base operation handler fix narrows the filter to ID fields, and the test validates the corrected behavior with the plugin hook present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@genu genu closed this Feb 11, 2026
@genu genu reopened this Feb 12, 2026
ymc9
ymc9 previously approved these changes Feb 22, 2026
Copy link
Member

@ymc9 ymc9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @genu , thanks for making the fix, and I think it's a good safety measure. A deeper problem is, when mutation hooks are used in plugins, the underlying query executor "forces injecting" a return * clause, resulting in more fields returned and breaking some assumptions on the upper layer. I'll see I can make a separate PR on the root cause.

I've merged your branch with the latest "dev" and refined the comments a bit. Will merge once CI passes

@ymc9 ymc9 merged commit d49c39e into zenstackhq:dev Feb 22, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Update on delegate child model fails with "missing FROM-clause entry" when entity mutation plugins are present

2 participants