CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • Association
  • AssociationCollection
  • Behavior
  • BehaviorRegistry
  • EagerLoader
  • Entity
  • Marshaller
  • Query
  • ResultSet
  • RulesChecker
  • SaveOptionsBuilder
  • Table
  • TableRegistry

Interfaces

  • PropertyMarshalInterface

Traits

  • AssociationsNormalizerTrait

Class AssociationCollection

A container/collection for association classes.

Contains methods for managing associations, and ordering operations around saving and deleting.

Cake\ORM\AssociationCollection implements IteratorAggregate uses Cake\ORM\AssociationsNormalizerTrait , Cake\ORM\Locator\LocatorAwareTrait
Namespace: Cake\ORM
Location: ORM/AssociationCollection.php

Properties summary

  • $_items protected
    Cake\ORM\Association[]
    Stored associations

Inherited Properties

  • _tableLocator

Method Summary

  • __construct() public
    Constructor.
  • _getNoCascadeItems() protected
    Returns items that have no cascade callback.
  • _save() protected
    Helper method for saving an association's data.
  • _saveAssociations() protected
    Helper method for saving an association's data.
  • add() public
    Add an association to the collection
  • cascadeDelete() public

    Cascade a delete across the various associations. Cascade first across associations for which cascadeCallbacks is true.

  • get() public
    Fetch an attached association by name.
  • getByProperty() public
    Fetch an association by property name.
  • getByType() public
    Get an array of associations matching a specific type.
  • getIterator() public
    Allow looping through the associations
  • has() public
    Check for an attached association by name.
  • keys() public
    Get the names of all the associations in the collection.
  • load() public
    Creates and adds the Association object to this collection.
  • normalizeKeys() public

    Returns an associative array of association names out a mixed array. If true is passed, then it returns all association names in this collection.

  • remove() public
    Drop/remove an association.
  • removeAll() public
    Remove all registered associations.
  • saveChildren() public
    Save all the associations that are children of the given entity.
  • saveParents() public
    Save all the associations that are parents of the given entity.
  • type() public deprecated
    Get an array of associations matching a specific type.

Method Detail

__construct() public ¶

__construct( Cake\ORM\Locator\LocatorInterface $tableLocator = null )

Constructor.

Sets the default table locator for associations. If no locator is provided, the global one will be used.

Parameters
Cake\ORM\Locator\LocatorInterface $tableLocator optional null
Table locator instance.

_getNoCascadeItems() protected ¶

_getNoCascadeItems( Cake\Datasource\EntityInterface $entity , array $options )

Returns items that have no cascade callback.

Parameters
Cake\Datasource\EntityInterface $entity
The entity to delete associations for.
array $options
The options used in the delete operation.
Returns
Cake\ORM\Association[]

_save() protected ¶

_save( Cake\ORM\Association $association , Cake\Datasource\EntityInterface $entity , array $nested , array $options )

Helper 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
boolean
Success

_saveAssociations() protected ¶

_saveAssociations( Cake\ORM\Table $table , Cake\Datasource\EntityInterface $entity , array $associations , array $options , boolean $owningSide )

Helper 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
boolean $owningSide

Compared with association classes' isOwningSide method.

Returns
boolean
Success
Throws
InvalidArgumentException
When an unknown alias is used.

add() public ¶

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.

Parameters
string $alias
The association alias
Cake\ORM\Association $association
The association to add.
Returns
Cake\ORM\Association
The association object being added.

cascadeDelete() public ¶

cascadeDelete( Cake\Datasource\EntityInterface $entity , array $options )

Cascade 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.

get() public ¶

get( string $alias )

Fetch an attached association by name.

Parameters
string $alias
The association alias to get.
Returns
Cake\ORM\Association|null
Either the association or null.

getByProperty() public ¶

getByProperty( string $prop )

Fetch an association by property name.

Parameters
string $prop
The property to find an association by.
Returns
Cake\ORM\Association|null
Either the association or null.

getByType() public ¶

getByType( string|string[] $class )

Get an array of associations matching a specific type.

Parameters
string|string[] $class

The type of associations you want. For example 'BelongsTo' or array like ['BelongsTo', 'HasOne']

Returns
array
An array of Association objects.
Since
3.5.3

getIterator() public ¶

getIterator( )

Allow looping through the associations

Returns
ArrayIterator
Implementation of
IteratorAggregate::getIterator()

has() public ¶

has( string $alias )

Check for an attached association by name.

Parameters
string $alias
The association alias to get.
Returns
boolean
Whether or not the association exists.

keys() public ¶

keys( )

Get the names of all the associations in the collection.

Returns
string[]

load() public ¶

load( string $className , string $associated , array $options = [] )

Creates and adds the Association object to this collection.

Parameters
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.
Returns
Cake\ORM\Association
Throws
InvalidArgumentException

normalizeKeys() public ¶

normalizeKeys( boolean|array $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.

Parameters
boolean|array $keys
the list of association names to normalize
Returns
array

remove() public ¶

remove( string $alias )

Drop/remove an association.

Once removed the association will not longer be reachable

Parameters
string $alias
The alias name.

removeAll() public ¶

removeAll( )

Remove all registered associations.

Once removed associations will not longer be reachable

saveChildren() public ¶

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.

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
boolean
Success

saveParents() public ¶

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.

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
boolean
Success

type() public deprecated ¶

type( string|array $class )

Get an array of associations matching a specific type.

Deprecated
3.5.3 Use getByType() instead.
Parameters
string|array $class

The type of associations you want. For example 'BelongsTo' or array like ['BelongsTo', 'HasOne']

Returns
array
An array of Association objects.

Methods used from Cake\ORM\AssociationsNormalizerTrait

_normalizeAssociations() protected ¶

_normalizeAssociations( array $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

Parameters
array $associations
The array of included associations.
Returns
array
An array having dot notation transformed into nested arrays

Methods used from Cake\ORM\Locator\LocatorAwareTrait

getTableLocator() public ¶

getTableLocator( )

Gets the table locator.

Returns
Cake\ORM\Locator\LocatorInterface

setTableLocator() public ¶

setTableLocator( Cake\ORM\Locator\LocatorInterface $tableLocator )

Sets the table locator.

Parameters
Cake\ORM\Locator\LocatorInterface $tableLocator
LocatorInterface instance.
Returns

$this

tableLocator() public deprecated ¶

tableLocator( Cake\ORM\Locator\LocatorInterface $tableLocator = null )

Sets the table locator. If no parameters are passed, it will return the currently used locator.

Deprecated
3.5.0 Use getTableLocator()/setTableLocator() instead.
Parameters
Cake\ORM\Locator\LocatorInterface $tableLocator optional null
LocatorInterface instance.
Returns
Cake\ORM\Locator\LocatorInterface

Properties detail

$_items ¶

protected Cake\ORM\Association[]

Stored associations

[]
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs