Class AssociationCollection
A container/collection for association classes.
Contains methods for managing associations, and ordering operations around saving and deleting.
Property Summary
- 
        $_items protectedarrayStored associations 
Method Summary
- 
          _normalizeAssociations() protectedReturns 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 
- 
          _save() protectedHelper method for saving an association's data. 
- 
          _saveAssociations() protectedHelper method for saving an association's data. 
- 
          add() publicAdd an association to the collection 
- 
          cascadeDelete() publicCascade a delete across the various associations. Cascade first across associations for which cascadeCallbacks is true. 
- 
          get() publicFetch an attached association by name. 
- 
          getByProperty() publicFetch an association by property name. 
- 
          getIterator() publicAllow looping through the associations 
- 
          has() publicCheck for an attached association by name. 
- 
          keys() publicGet the names of all the associations in the collection. 
- 
          normalizeKeys() publicReturns an associative array of association names out a mixed array. If true is passed, then it returns all association names in this collection. 
- 
          remove() publicDrop/remove an association. 
- 
          removeAll() publicRemove all registered associations. 
- 
          saveChildren() publicSave all the associations that are children of the given entity. 
- 
          saveParents() publicSave all the associations that are parents of the given entity. 
- 
          type() publicGet an array of associations matching a specific type. 
Method Detail
_normalizeAssociations() ¶ protected
_normalizeAssociations(array $associations): arrayReturns 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
Parameters
- 
                array$associations
- The array of included associations. 
Returns
arrayAn array having dot notation transformed into nested arrays
_save() ¶ protected
_save(Cake\ORM\Association $association, Cake\Datasource\EntityInterface $entity, array $nested, array $options): boolHelper method for saving an association's data.
Parameters
- 
                Cake\ORM\Association$association
- The association object to save with. 
- 
                Cake\Datasource\EntityInterface$entity
- The entity to save 
- 
                array$nested
- Options for deeper associations 
- 
                array$options
- Original options 
Returns
boolSuccess
_saveAssociations() ¶ protected
_saveAssociations(Cake\ORM\Table $table, Cake\Datasource\EntityInterface $entity, array $associations, array $options, bool $owningSide): boolHelper method for saving an association's data.
Parameters
- 
                Cake\ORM\Table$table
- The table the save is currently operating on 
- 
                Cake\Datasource\EntityInterface$entity
- The entity to save 
- 
                array$associations
- Array of associations to save. 
- 
                array$options
- Original options 
- 
                bool$owningSide
- Compared with association classes' isOwningSide method. 
Returns
boolSuccess
Throws
InvalidArgumentExceptionWhen an unknown alias is used.
add() ¶ public
add(string $alias, Cake\ORM\Association $association): Cake\ORM\AssociationAdd an association to the collection
If the alias added contains a . the part preceding the . will be dropped.
This makes using plugins simpler as the Plugin.Class syntax is frequently used.
Parameters
- 
                string$alias
- The association alias 
- 
                Cake\ORM\Association$association
- The association to add. 
Returns
Cake\ORM\AssociationThe association object being added.
cascadeDelete() ¶ public
cascadeDelete(Cake\Datasource\EntityInterface $entity, array $options): voidCascade a delete across the various associations. Cascade first across associations for which cascadeCallbacks is true.
Parameters
- 
                Cake\Datasource\EntityInterface$entity
- The entity to delete associations for. 
- 
                array$options
- The options used in the delete operation. 
Returns
voidget() ¶ public
get(string $alias): Cake\ORM\Association|nullFetch an attached association by name.
Parameters
- 
                string$alias
- The association alias to get. 
Returns
Cake\ORM\Association|nullEither the association or null.
getByProperty() ¶ public
getByProperty(string $prop): Cake\ORM\Association|nullFetch an association by property name.
Parameters
- 
                string$prop
- The property to find an association by. 
Returns
Cake\ORM\Association|nullEither the association or null.
getIterator() ¶ public
getIterator(): ArrayIteratorAllow looping through the associations
Returns
ArrayIteratorhas() ¶ public
has(string $alias): boolCheck for an attached association by name.
Parameters
- 
                string$alias
- The association alias to get. 
Returns
boolWhether or not the association exists.
keys() ¶ public
keys(): arrayGet the names of all the associations in the collection.
Returns
arraynormalizeKeys() ¶ public
normalizeKeys(bool|array $keys): arrayReturns an associative array of association names out a mixed array. If true is passed, then it returns all association names in this collection.
Parameters
- 
                bool|array$keys
- the list of association names to normalize 
Returns
arrayremove() ¶ public
remove(string $alias): voidDrop/remove an association.
Once removed the association will not longer be reachable
Parameters
- 
                string$alias
- The alias name. 
Returns
voidremoveAll() ¶ public
removeAll(): voidRemove all registered associations.
Once removed associations will not longer be reachable
Returns
voidsaveChildren() ¶ public
saveChildren(Cake\ORM\Table $table, Cake\Datasource\EntityInterface $entity, array $associations, array $options): boolSave all the associations that are children of the given entity.
Child associations include any association where the given table is not the owning side.
Parameters
- 
                Cake\ORM\Table$table
- The table entity is for. 
- 
                Cake\Datasource\EntityInterface$entity
- The entity to save associated data for. 
- 
                array$associations
- The list of associations to save children from. associations not in this list will not be saved. 
- 
                array$options
- The options for the save operation. 
Returns
boolSuccess
saveParents() ¶ public
saveParents(Cake\ORM\Table $table, Cake\Datasource\EntityInterface $entity, array $associations, array $options = []): boolSave all the associations that are parents of the given entity.
Parent associations include any association where the given table is the owning side.
Parameters
- 
                Cake\ORM\Table$table
- The table entity is for. 
- 
                Cake\Datasource\EntityInterface$entity
- The entity to save associated data for. 
- 
                array$associations
- The list of associations to save parents from. associations not in this list will not be saved. 
- 
                array$options optional
- The options for the save operation. 
Returns
boolSuccess
type() ¶ public
type(string|array $class): arrayGet an array of associations matching a specific type.
Parameters
- 
                string|array$class
- The type of associations you want. For example 'BelongsTo' or array like ['BelongsTo', 'HasOne'] 
Returns
arrayAn array of Association objects.
