FieldExpansion extension provides a
Controller#expanded_fields helper for processing
:fields params to determine the final set of fields necessary to process the request.
Either, or both, of the
:fields params may be used, provided they are defined with the proper types:
:viewmust be of type
Symbol, for example:
attribute :view, Symbol.
Praxis::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.
The exact expansion depends upon both the parameters defined on the action in question:
- If neither
: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 the
MediaTypeare expanded. If no fields were selected in the request, the
:defaultview is expanded .
- If both
: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.