Skip to content

Keep field expression keys in patch() and merge() data when building the query (#53) - #342

Merged
lehni merged 1 commit into
nextfrom
fix/rc-json-pure
Oct 12, 2026
Merged

lehni merged 1 commit into
nextfrom
fix/rc-json-pure

Conversation

@lehni

@lehni lehni commented Oct 12, 2026 •

Copy link
Copy Markdown

What

convertFieldExpressionsToRaw() no longer deletes the field expression keys like 'meta:color' from the model of patch() and merge() while it builds the knex query. UpdateOperation.onAfter2() removes them from the patched model once the write has run, after $afterUpdate(), matched by property name like checkFieldExpressions(). All writes that return or merge their patch model go through it: $query().patch(), patchAndFetch*() and the patches of upsertGraph().

Why

Building the query mutated its data, so building it a second time lost the JSON writes: toKnexQuery() or toString() and then running the query, or building a clone() (which shares the model), resolved to 0 without any SQL. The keys were also deleted by their column names, which missed them with snakeCaseMappers(), so $query().patch({ 'extraMeta:color': 'red' }) left an extraMeta:color property on the instance.

Breaking

The patched model keeps its field expression keys until the write has run, so instance $afterUpdate() hooks now see them, as $beforeUpdate() does. A model instance passed to patch() loses them after the write, as before. Running the same query object a second time after it has run still writes no field expressions, as the removal applies to the model it shares with its clones.

Tests

In tests/integration/misc/fieldExpressionKeys.js:

  • patch() should write an undeclared key with a colon to the json path when built before (toKnexQuery() on the query and on a clone first)
  • merge() should write an undeclared key with a colon to the json path when built before
  • $query().patch() should not set the keys with a colon mapped by snakeCaseMappers
  • upsertGraph() should not return the undeclared keys with a colon
  • patchAndFetchById() should not return the undeclared keys with a colon

The first three fail on next. The upsertGraph() test fails with the removal done per operation, as in the first version of this PR. The patchAndFetchById() test also passes before the change; it covers the removal for *AndFetch.

Part of #53.

@lehni lehni added the 4.0 Breaking change, deferred to 4.0 (#53) label Oct 12, 2026
@lehni
lehni merged commit a1d1877 into next Oct 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 Breaking change, deferred to 4.0 (#53)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant