Trait AssociationsNormalizerTrait
Contains methods for parsing the associated tables array that is typically passed to a save operation
Property Summary
-
$associationOptions protected
array<string, int>List of option names accepted inside an association's options array.
Unknown string keys are treated as nested association aliases so that contain-style associated arrays also work with lowercase aliases.
Method Summary
-
extractAssociations() protected
Extracts association names from options array, separating them from actual options.
This allows a contain-style nested array format in the shared
associatedoption:- ['Users', 'Comments'] contains nested associations
- ['Users' => [...], 'Comments'] contains nested associations
- ['onlyIds' => true, 'validate' => false] contains options
- ['Users', 'onlyIds' => true] contains associations and options
-
normalizeAssociations() protected
Returns an array out of the original passed associations list where dot notation is transformed into nested arrays so that they can be parsed by other routines.
This method now supports the same nested array format as contain(), allowing:
- Dot notation: ['First.Second']
- Nested arrays: ['First' => ['Second', 'Third']]
- Mixed with options: ['First' => ['Second', 'onlyIds' => true]]
Known option names are parsed as options. Unknown string keys are parsed as association aliases. If an association alias collides with an option name, use dot notation or the explicit
associatedoption.
Method Detail
extractAssociations() ¶ protected
extractAssociations(array $options): array
Extracts association names from options array, separating them from actual options.
This allows a contain-style nested array format in the shared associated
option:
- ['Users', 'Comments'] contains nested associations
- ['Users' => [...], 'Comments'] contains nested associations
- ['onlyIds' => true, 'validate' => false] contains options
- ['Users', 'onlyIds' => true] contains associations and options
Parameters
-
array$options The options array that may contain nested associations.
Returns
arrayAn array with two elements: [associations, options]
normalizeAssociations() ¶ protected
normalizeAssociations(array|string $associations): array
Returns an array out of the original passed associations list where dot notation is transformed into nested arrays so that they can be parsed by other routines.
This method now supports the same nested array format as contain(), allowing:
- Dot notation: ['First.Second']
- Nested arrays: ['First' => ['Second', 'Third']]
- Mixed with options: ['First' => ['Second', 'onlyIds' => true]]
Known option names are parsed as options. Unknown string keys are parsed as
association aliases. If an association alias collides with an option name,
use dot notation or the explicit associated option.
Parameters
-
array|string$associations The array of included associations.
Returns
arrayAn array having dot notation transformed into nested arrays
Property Detail
$associationOptions ¶ protected
List of option names accepted inside an association's options array.
Unknown string keys are treated as nested association aliases so that contain-style associated arrays also work with lowercase aliases.
Type
array<string, int>