FieldExpansion Extension
The FieldExpansion extension provides a Controller#expanded_fields helper for processing :view and/or :fields params to determine the final set of fields necessary to process the request.
Either, or both, of the :view and :fields params may be used, provided they are defined with the proper types:
:viewmust be of typeSymbol, for example:attribute :view, Symbol.:fieldsmust bePraxis::Types::FieldSelector(or a scoped subclass), for example:attribute :fields, Praxis::Types::FieldSelector.for(Person).
Regardless of what attributes are used, any attributes with types that are either a MediaType or a collection of a MediaType will be recursively expanded into a complete set of “leaf” attributes.
Expansion logic
The exact expansion depends upon both the parameters defined on the action in question:
- If neither 
:viewor:fieldsare defined in the action: the:defaultview will always be expanded. - If only 
:viewis defined in the action: the system will expand the view name specified in the incoming request (or will use the:defaultview if one was not passed in the request). - If only 
:fieldsis defined in the action: the selected attributes from theMediaTypeare expanded. If no fields were selected in the request, the:defaultview is expanded . - If both 
:viewand:fieldsare defined in the action: the system will expand view name passed in the request (or:defaultif none was passed), but restricted to the selectable fields that were passed in. In other words, will perform a intersection of the fields from the view and the fields passed in the request parameter.