feat: return empty relationships for new entities - #304
Conversation
|
Issue #131 is the earlier version of #177 and is covered by this implementation’s default behavior. The public regression calls to-one and to-many getters on brand-new entities, verifies null/empty-array results, and verifies no SQL runs. I added |
Additional issue reviews: #148 and #131Addresses #148. Fit score: 8/10. Addresses #131. Fit score: 7/10. Returning the relationship default for a new entity makes fill/default workflows practical, but globally returning null can hide misspelled relationship names. This implementation keeps helpful errors for nonexistent relationships while returning the defined empty/default value for valid unloaded relationships. |
Closes #177
Closes #148
Closes #131
Issue review
#177 / #131 — empty relationship values for new entities
Recommendation: 9/10. New entities should expose a relationship type's normal empty value instead of forcing loaded-state branching in forms, post-fill defaults, interceptors, and mementos. This should be the default rather than an opt-in setting so a relationship getter has the same value shape on new and loaded entities.
#148 — improve
retrieveRelationship()Recommendation: 9/10. The explicit relationship-cache API should validate names and provide predictable defaults.
Reasons in favor:
nullor a configured default entity;Tradeoffs:
retrieveRelationship()now marks its default value loaded, so callers choosing this low-level cache API are intentionally suppressing a later lazy-load query;Reproduction
Public API tests reproduced the prior behavior:
QuickEntityNotLoaded, including the Return nulls instead of throwing an error when attempting to access a relationship on an unloaded entity #131 post-fill pattern;retrieveRelationship("posts")returned null instead of an empty collection;Before the #148 implementation, its focused bundle reported 9 passed, 1 failure, and 2 errors.
Implementation
initRelation()behavior.retrieveRelationship().withDefault()entities and empty arrays for collection relationships.Validation
box run-script formatgit diff --checkqb 14.0.0-beta.3(qb@be).