Skip to content

feat: support select/omit projections on populates#1628

Open
luislobo wants to merge 1 commit intobalderdashy:masterfrom
luislobo:feat/populate-projections
Open

feat: support select/omit projections on populates#1628
luislobo wants to merge 1 commit intobalderdashy:masterfrom
luislobo:feat/populate-projections

Conversation

@luislobo
Copy link
Contributor

Summary

  • teach to snapshot the original populate instructions and apply the requested / projection after unserializing populated child records; this keeps adapter quirks from leaking extra attributes
  • allow singular () populates to specify / ; we validate the shapes, require array syntax, auto-include the child PK, reject unknown / collection attributes, and block custom projections when the associated model is
  • build out regression coverage for the happy path and every new error branch (bad types, unknown fields, collection / PK references, schema:false models), derived from sailscastshq/waterline@414c927

Why

Waterline already supports / on top-level criteria, but populated singular associations silently ignored those directives. Adapters that don’t implement column-level projections returned fully hydrated child rows, so API users had no reliable way to trim sensitive attributes out of populated associations.
The validation code also rejected otherwise reasonable populate subcriteria, making it impossible to express / even if we applied them ourselves.

This change brings singular populates up to parity with top-level projections, keeps adapters honest, and documents the exact set of error cases developers should expect when they misuse the feature.

How

  1. Capture the original dictionary in , then run a tiny projector over every populated child record once we’ve transformed column names back into attribute names.
  2. Extend the singular-attribute normalization branch in so that:
    • only , , or are accepted
    • the arrays contain strings that resolve to real attributes on the associated model
    • the associated model’s primary key remains selected
    • schema:false associated models continue to forbid custom projections
  3. Port the sailscastshq test additions and expand them to exercise every failure mode (non-arrays, non-strings, unknown attributes, collection attributes, schema:false usage, PK omission).

Testing

  • npm test

## Summary

- capture original populate subcriteria in help-find and apply select/omit filters after unserializing populated records so adapters that ignore projections still return trimmed data

- allow singular populate subcriteria to specify select/omit in forge-stage-two-query with strong validation (arrays only, known/non-collection attributes, preserved child PK, schema:false restrictions)

- add comprehensive regression tests for valid projections and every E_INVALID_POPULATES branch, adapted from sailscastshq/waterline@414c9275

## Testing

- npm test
@luislobo
Copy link
Contributor Author

luislobo commented Oct 3, 2025

Resolves balderdashy/sails#4667

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant