Trait AssociationsNormalizerTrait
Contains methods for parsing the associated tables array that is typically passed to a save operation
Method Summary
-
_extractAssociations() protected
Extracts association names from options array, separating them from actual 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.
-
_shouldExtractAssociations() protected
Determines if an array should have associations extracted from it.
Method Detail
_extractAssociations() ¶ protected
_extractAssociations(array $options): array
Extracts association names from options array, separating them from actual options.
Uses CakePHP naming conventions to distinguish associations from options:
- Association names start with uppercase (CamelCase): Users, Articles
- Special data keys start with underscore: _joinData, _ids (treated as associations)
- Option keys start with lowercase (camelCase): onlyIds, conditions
This allows the same nested array format as contain():
- ['Users', 'Comments'] → associations
- ['Users' => [...], 'Comments'] → associations
- ['onlyIds' => true, 'validate' => false] → options only
- ['Users', 'onlyIds' => true] → mixed
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]]
Parameters
-
array|string$associations The array of included associations.
Returns
arrayAn array having dot notation transformed into nested arrays
_shouldExtractAssociations() ¶ protected
_shouldExtractAssociations(array $options): bool
Determines if an array should have associations extracted from it.
Returns true if the array appears to be mixing association names with options, or if it contains nested association structures (like contain() format). Returns false for simple arrays that should be kept as-is.
Uses CakePHP naming conventions to detect associations vs options:
- Association names start with uppercase (CamelCase): Users, Articles
- Option keys start with lowercase (camelCase): onlyIds, conditions
- Special data keys start with underscore: _joinData, _ids
Parameters
-
array$options The options array to check.
Returns
bool