Skip to content

feat: support virtual attribute defaults - #328

Open
elpete wants to merge 1 commit into
nextfrom
feat/113-virtual-attribute-default
Open

feat: support virtual attribute defaults#328
elpete wants to merge 1 commit into
nextfrom
feat/113-virtual-attribute-default

Conversation

@elpete

@elpete elpete commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Closes #113

Review

This improvement is a good fit for Quick. Virtual projections often represent counts or booleans, and a new entity needs a meaningful value before a query has populated the projection.

Recommendation: 9/10.

Reasons for

  • Avoids an unnecessary database refresh after saving a newly constructed entity.
  • Makes virtual attributes behave more like declared properties with defaults.
  • Ensures API mementos have stable types such as false instead of an empty string.
  • Carries the default through newEntity() metadata reuse.

Reasons against

  • This intentionally changes the positional meaning of the second argument.
  • Callers that currently use appendVirtualAttribute( name, true ) to exclude an attribute must move that flag to the third argument or use the named excludeFromMemento argument.
  • Dynamically mutating an entity's memento includes requires care when custom memento configuration is present.

Implementation

  • Changes the signature to appendVirtualAttribute( name, defaultValue, excludeFromMemento = false ) on both BaseEntity and QuickBuilder.
  • Stores the default in virtual-attribute metadata and initializes it on the current entity and entities produced by newEntity().
  • Adds a dynamically appended virtual attribute to default memento includes unless explicitly excluded.
  • Preserves named internal excludeFromMemento calls.

Test-first evidence

Before implementation, the public magic getter returned an empty string for appendVirtualAttribute( "hasPosts", false ); the new test failed with Expected [false] but received [""].

Tests now verify:

  • a false default through the generated/magic getter;
  • the default in the normal memento flow;
  • propagation through newEntity(); and
  • the third-position memento exclusion flag.

Validation

  • Attribute, memento, and subquery specs: 35 passed, 0 failed, 0 errors
  • Full suite: 497 passed, 0 failed, 0 errors, 3 skipped
  • Formatter completed
  • git diff --check passed
  • Tested with 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