Skip to content

fix: preserve entity keys in selected columns - #348

Open
elpete wants to merge 1 commit into
nextfrom
issue/45
Open

fix: preserve entity keys in selected columns#348
elpete wants to merge 1 commit into
nextfrom
issue/45

Conversation

@elpete

@elpete elpete commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Closes #45

Issue review

Fit score: 9/10. A loaded Quick entity needs its complete key to retain identity and support refresh, update, delete, and relationship behavior. Explicit column selection should narrow payload columns without creating an entity that appears loaded but has no identity.

Reasons for

  • preserves the core entity identity invariant
  • prevents subtle failures after otherwise successful reads
  • supports composite keys as well as single-column keys

Reasons against

  • callers cannot use entity hydration to omit key columns from returned SQL
  • raw/query projections that intentionally exclude keys should use asQuery() instead

Implementation

  • ensures key columns are selected immediately before an entity-hydrating get, first, paginate, or simplePaginate execution
  • leaves scalar subqueries and asQuery() projections untouched
  • avoids duplicating key columns already selected

Reproduction

The new public-API test failed before the fix: User.select( "username" ).findOrFail( 1 ) returned a loaded entity whose getId() was null.

Validation

  • focused column/subquery/relationship-ordering coverage: 20 passed, 0 failed, 0 errors
  • full suite: 497 passed, 0 failed, 0 errors, 3 skipped
  • box run-script format
  • git diff --check
  • qb dependency: 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