Skip to content

Refresh database-generated attributes on save - #338

Open
elpete wants to merge 1 commit into
nextfrom
feat/58-refresh-on-save
Open

Refresh database-generated attributes on save#338
elpete wants to merge 1 commit into
nextfrom
feat/58-refresh-on-save

Conversation

@elpete

@elpete elpete commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Closes #58

Issue review

Recommendation: 9/10 — implement. Database-generated timestamps, computed columns, and trigger-updated values are common, and requiring callers to remember a separate refresh() leaves saved entities stale. A property-level opt-in keeps the extra query explicit. The tradeoff is one additional select for saves on entities that use the flag.

Implementation

  • adds the boolean property metadata refreshOnSave (default false)
  • re-reads flagged attributes after both inserts and updates
  • refreshes after generated primary keys are assigned
  • bypasses global scopes when looking up the row that was just persisted
  • updates original attribute state so refreshed values are not dirty
  • makes refreshed values available to post-insert/post-update/post-save observers

Test-first evidence

The public save regression initially errored because the database-default created_date remained null on the saved entity. With refreshOnSave=true, the entity receives the database timestamp immediately and remains clean.

Validation

  • focused SaveSpec: 19 passed, 0 failed, 0 errors
  • full Lucee 6 suite: 496 passed, 0 failed, 0 errors, 3 skipped
  • box run-script format
  • git diff --check

Uses qb@14.0.0-beta.3.

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.

1 participant