A container/collection for association classes.
Contains methods for managing associations, and ordering operations around saving and deleting.
\Cake\ORM\Association[]
Stored associations
\Cake\ORM\Locator\LocatorInterface|null
Table locator instance
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
Returns an associative array of association names out a mixed array. If true is passed, then it returns all association names in this collection.
__construct(?\Cake\ORM\Locator\LocatorInterface $tableLocator)
Constructor.
Sets the default table locator for associations. If no locator is provided, the global one will be used.
\Cake\ORM\Locator\LocatorInterface|null
$tableLocator optional Table locator instance.
_normalizeAssociations(mixed $associations)
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
array|string
$associations The array of included associations.
array
An array having dot notation transformed into nested arrays
_save(\Cake\ORM\Association $association, \Cake\Datasource\EntityInterface $entity, array $nested, array $options)
Helper method for saving an association's data.
\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
bool
Success
_saveAssociations(\Cake\ORM\Table $table, \Cake\Datasource\EntityInterface $entity, array $associations, array $options, bool $owningSide)
Helper method for saving an association's data.
\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.
bool
Success
InvalidArgumentException
add(string $alias, \Cake\ORM\Association $association)
Add 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.
string
$alias The association alias
\Cake\ORM\Association
$association The association to add.
\Cake\ORM\Association
The association object being added.
cascadeDelete(\Cake\Datasource\EntityInterface $entity, array $options)
Cascade a delete across the various associations.
Cascade first across associations for which cascadeCallbacks is true.
\Cake\Datasource\EntityInterface
$entity The entity to delete associations for.
array
$options The options used in the delete operation.
bool
get(string $alias)
Fetch an attached association by name.
string
$alias The association alias to get.
\Cake\ORM\Association|null
Either the association or null.
getByProperty(string $prop)
Fetch an association by property name.
string
$prop The property to find an association by.
\Cake\ORM\Association|null
Either the association or null.
getByType(mixed $class)
Get an array of associations matching a specific type.
string|array
$class The type of associations you want. For example 'BelongsTo' or array like ['BelongsTo', 'HasOne']
\Cake\ORM\Association[]
An array of Association objects.
getIterator()
Allow looping through the associations
\Cake\ORM\Association[]
getTableLocator()
Gets the table locator.
\Cake\ORM\Locator\LocatorInterface
has(string $alias)
Check for an attached association by name.
string
$alias The association alias to get.
bool
Whether or not the association exists.
keys()
Get the names of all the associations in the collection.
string[]
load(string $className, string $associated, array $options)
Creates and adds the Association object to this collection.
string
$className The name of association class.
string
$associated The alias for the target table.
array
$options optional List of options to configure the association definition.
\Cake\ORM\Association
InvalidArgumentException
normalizeKeys(mixed $keys)
Returns an associative array of association names out a mixed array. If true is passed, then it returns all association names in this collection.
bool|array
$keys the list of association names to normalize
array
remove(string $alias)
Drop/remove an association.
Once removed the association will not longer be reachable
string
$alias The alias name.
removeAll()
Remove all registered associations.
Once removed associations will not longer be reachable
saveChildren(\Cake\ORM\Table $table, \Cake\Datasource\EntityInterface $entity, array $associations, array $options)
Save all the associations that are children of the given entity.
Child associations include any association where the given table is not the owning side.
\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.
bool
Success
saveParents(\Cake\ORM\Table $table, \Cake\Datasource\EntityInterface $entity, array $associations, array $options)
Save all the associations that are parents of the given entity.
Parent associations include any association where the given table is the owning side.
\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.
bool
Success
setTableLocator(\Cake\ORM\Locator\LocatorInterface $tableLocator)
Sets the table locator.
\Cake\ORM\Locator\LocatorInterface
$tableLocator LocatorInterface instance.
$this
Stored associations
\Cake\ORM\Association[]
Table locator instance
\Cake\ORM\Locator\LocatorInterface|null
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.1/class-Cake.ORM.AssociationCollection.html