\Cake\ORM\AssociationHasMany

Represents an N - 1 relationship where the target side of the relationship will have one or multiple records per each one in the source side.

An example of a HasMany association would be Author has many Articles.

Summary

Methods
Properties
Constants
__construct()
setName()
getName()
name()
setCascadeCallbacks()
getCascadeCallbacks()
cascadeCallbacks()
setClassName()
getClassName()
className()
setSource()
getSource()
source()
setTarget()
getTarget()
target()
setConditions()
getConditions()
conditions()
setBindingKey()
getBindingKey()
bindingKey()
getForeignKey()
setForeignKey()
foreignKey()
setDependent()
getDependent()
dependent()
canBeJoined()
setJoinType()
getJoinType()
joinType()
setProperty()
getProperty()
property()
setStrategy()
getStrategy()
strategy()
getFinder()
setFinder()
finder()
attachTo()
transformRow()
defaultRowValue()
find()
exists()
updateAll()
deleteAll()
requiresKeys()
__get()
__isset()
__call()
type()
eagerLoader()
cascadeDelete()
isOwningSide()
saveAssociated()
tableLocator()
setTableLocator()
getTableLocator()
setSaveStrategy()
getSaveStrategy()
saveStrategy()
link()
unlink()
replace()
setSort()
getSort()
sort()
No public properties found
STRATEGY_JOIN
STRATEGY_SUBQUERY
STRATEGY_SELECT
ONE_TO_ONE
ONE_TO_MANY
MANY_TO_MANY
MANY_TO_ONE
SAVE_APPEND
SAVE_REPLACE
_propertyName()
_options()
_appendNotMatching()
_dispatchBeforeFind()
_appendFields()
_formatAssociationResults()
_bindNewAssociations()
_joinCondition()
_extractFinder()
_getClassName()
_fixtureName()
_entityName()
_modelKey()
_modelNameFromKey()
_singularName()
_variableName()
_singularHumanName()
_camelize()
_pluralHumanName()
_pluginPath()
_pluginNamespace()
_saveTarget()
_unlinkAssociated()
_unlink()
_foreignKeyAcceptsNull()
$_name
$_className
$_bindingKey
$_foreignKey
$_conditions
$_dependent
$_cascadeCallbacks
$_sourceTable
$_targetTable
$_joinType
$_propertyName
$_strategy
$_finder
$_validStrategies
$_tableLocator
$_sort
$_saveStrategy
N/A
No private methods found
No private properties found
N/A

Constants

STRATEGY_JOIN

STRATEGY_JOIN = 'join' : string

Strategy name to use joins for fetching associated records

STRATEGY_SUBQUERY

STRATEGY_SUBQUERY = 'subquery' : string

Strategy name to use a subquery for fetching associated records

STRATEGY_SELECT

STRATEGY_SELECT = 'select' : string

Strategy name to use a select for fetching associated records

ONE_TO_ONE

ONE_TO_ONE = 'oneToOne' : string

Association type for one to one associations.

ONE_TO_MANY

ONE_TO_MANY = 'oneToMany' : string

Association type for one to many associations.

MANY_TO_MANY

MANY_TO_MANY = 'manyToMany' : string

Association type for many to many associations.

MANY_TO_ONE

MANY_TO_ONE = 'manyToOne' : string

Association type for many to one associations.

SAVE_APPEND

SAVE_APPEND = 'append' : string

Saving strategy that will only append to the links set

SAVE_REPLACE

SAVE_REPLACE = 'replace' : string

Saving strategy that will replace the links with the provided set

Properties

$_name

$_name : string

Name given to the association, it usually represents the alias assigned to the target associated table

Type

string

$_className

$_className : string

The class name of the target table object

Type

string

$_bindingKey

$_bindingKey : string|array

The field name in the owning side table that is used to match with the foreignKey

Type

string|array

$_foreignKey

$_foreignKey : string|array

The name of the field representing the foreign key to the table to load

Type

string|array

$_conditions

$_conditions : array|callable

A list of conditions to be always included when fetching records from the target association

Type

array|callable

$_dependent

$_dependent : boolean

Whether the records on the target table are dependent on the source table, often used to indicate that records should be removed if the owning record in the source table is deleted.

Type

boolean

$_cascadeCallbacks

$_cascadeCallbacks : boolean

Whether or not cascaded deletes should also fire callbacks.

Type

boolean

$_sourceTable

$_sourceTable : \Cake\ORM\Table

Source table instance

Type

\Cake\ORM\Table

$_targetTable

$_targetTable : \Cake\ORM\Table

Target table instance

Type

\Cake\ORM\Table

$_joinType

$_joinType : string

The type of join to be used when adding the association to a query

Type

string

$_propertyName

$_propertyName : string

The property name that should be filled with data from the target table in the source table record.

Type

string

$_strategy

$_strategy : string

The strategy name to be used to fetch associated records.

Type

string

$_finder

$_finder : string|array

The default finder name to use for fetching rows from the target table With array value, finder name and default options are allowed.

Type

string|array

$_validStrategies

$_validStrategies : array

Valid strategies for this type of association

Type

array

$_sort

$_sort : mixed

Order in which target records should be returned

Type

mixed

$_saveStrategy

$_saveStrategy : string

Saving strategy to be used by this association

Type

string

Methods

__construct()

__construct(string  $alias, array  $options = array()) 

Constructor. Subclasses can override _options function to get the original list of passed options if expecting any other special key

Parameters

string $alias

The name given to the association

array $options

A list of properties to be set on this object

setName()

setName(string  $name) : $this

Sets the name for this association, usually the alias assigned to the target associated table

Parameters

string $name

Name to be assigned

Returns

$this

getName()

getName() : string

Gets the name for this association, usually the alias assigned to the target associated table

Returns

string

name()

name(string|null  $name = null) : string

Sets the name for this association.

Parameters

string|null $name

Name to be assigned

Returns

string

setCascadeCallbacks()

setCascadeCallbacks(boolean  $cascadeCallbacks) : $this

Sets whether or not cascaded deletes should also fire callbacks.

Parameters

boolean $cascadeCallbacks

cascade callbacks switch value

Returns

$this

getCascadeCallbacks()

getCascadeCallbacks() : boolean

Gets whether or not cascaded deletes should also fire callbacks.

Returns

boolean

cascadeCallbacks()

cascadeCallbacks(boolean|null  $cascadeCallbacks = null) : boolean

Sets whether or not cascaded deletes should also fire callbacks. If no arguments are passed, the current configured value is returned

Parameters

boolean|null $cascadeCallbacks

cascade callbacks switch value

Returns

boolean

setClassName()

setClassName(string  $className) : $this

Sets the class name of the target table object.

Parameters

string $className

Class name to set.

Throws

\InvalidArgumentException

In case the class name is set after the target table has been resolved, and it doesn't match the target table's class name.

Returns

$this

getClassName()

getClassName() : string

Gets the class name of the target table object.

Returns

string

className()

className() : string

The class name of the target table object

Returns

string

setSource()

setSource(\Cake\ORM\Table  $table) : $this

Sets the table instance for the source side of the association.

Parameters

\Cake\ORM\Table $table

the instance to be assigned as source side

Returns

$this

getSource()

getSource() : \Cake\ORM\Table

Gets the table instance for the source side of the association.

Returns

\Cake\ORM\Table

source()

source(\Cake\ORM\Table|null  $table = null) : \Cake\ORM\Table

Sets the table instance for the source side of the association. If no arguments are passed, the current configured table instance is returned

Parameters

\Cake\ORM\Table|null $table

the instance to be assigned as source side

Returns

\Cake\ORM\Table

setTarget()

setTarget(\Cake\ORM\Table  $table) : $this

Sets the table instance for the target side of the association.

Parameters

\Cake\ORM\Table $table

the instance to be assigned as target side

Returns

$this

getTarget()

getTarget() : \Cake\ORM\Table

Gets the table instance for the target side of the association.

Returns

\Cake\ORM\Table

target()

target(\Cake\ORM\Table|null  $table = null) : \Cake\ORM\Table

Sets the table instance for the target side of the association. If no arguments are passed, the current configured table instance is returned

Parameters

\Cake\ORM\Table|null $table

the instance to be assigned as target side

Returns

\Cake\ORM\Table

setConditions()

setConditions(array|callable  $conditions) : $this

Sets a list of conditions to be always included when fetching records from the target association.

Parameters

array|callable $conditions

list of conditions to be used

Returns

$this

getConditions()

getConditions() : array|callable

Gets a list of conditions to be always included when fetching records from the target association.

Returns

array|callable

conditions()

conditions(array|null  $conditions = null) : array|callable

Sets a list of conditions to be always included when fetching records from the target association. If no parameters are passed the current list is returned

Parameters

array|null $conditions

list of conditions to be used

Returns

array|callable

setBindingKey()

setBindingKey(string|array  $key) : $this

Sets the name of the field representing the binding field with the target table.

When not manually specified the primary key of the owning side table is used.

Parameters

string|array $key

the table field or fields to be used to link both tables together

Returns

$this

getBindingKey()

getBindingKey() : string|array

Gets the name of the field representing the binding field with the target table.

When not manually specified the primary key of the owning side table is used.

Returns

string|array

bindingKey()

bindingKey(string|null  $key = null) : string|array

Sets the name of the field representing the binding field with the target table.

When not manually specified the primary key of the owning side table is used.

If no parameters are passed the current field is returned

Parameters

string|null $key

the table field to be used to link both tables together

Returns

string|array

getForeignKey()

getForeignKey() : string

Gets the name of the field representing the foreign key to the source table.

Returns

string

setForeignKey()

setForeignKey(string|array  $key) : $this

Sets the name of the field representing the foreign key to the target table.

Parameters

string|array $key

the key or keys to be used to link both tables together

Returns

$this

foreignKey()

foreignKey(string|null  $key = null) : string|array

Sets the name of the field representing the foreign key to the target table.

If no parameters are passed the current field is returned

Parameters

string|null $key

the key to be used to link both tables together

Returns

string|array

setDependent()

setDependent(boolean  $dependent) : $this

Sets whether the records on the target table are dependent on the source table.

This is primarily used to indicate that records should be removed if the owning record in the source table is deleted.

If no parameters are passed the current setting is returned.

Parameters

boolean $dependent

Set the dependent mode. Use null to read the current state.

Returns

$this

getDependent()

getDependent() : boolean

Sets whether the records on the target table are dependent on the source table.

This is primarily used to indicate that records should be removed if the owning record in the source table is deleted.

Returns

boolean

dependent()

dependent(boolean|null  $dependent = null) : boolean

Sets whether the records on the target table are dependent on the source table.

This is primarily used to indicate that records should be removed if the owning record in the source table is deleted.

If no parameters are passed the current setting is returned.

Parameters

boolean|null $dependent

Set the dependent mode. Use null to read the current state.

Returns

boolean

canBeJoined()

canBeJoined(array  $options = array()) : boolean

Whether this association can be expressed directly in a query join

Parameters

array $options

custom options key that could alter the return value

Returns

boolean —

if the 'matching' key in $option is true then this function will return true, false otherwise

setJoinType()

setJoinType(string  $type) : $this

Sets the type of join to be used when adding the association to a query.

Parameters

string $type

the join type to be used (e.g. INNER)

Returns

$this

getJoinType()

getJoinType() : string

Gets the type of join to be used when adding the association to a query.

Returns

string

joinType()

joinType(string|null  $type = null) : string

Sets the type of join to be used when adding the association to a query.

If no arguments are passed, the currently configured type is returned.

Parameters

string|null $type

the join type to be used (e.g. INNER)

Returns

string

setProperty()

setProperty(string  $name) : $this

Sets the property name that should be filled with data from the target table in the source table record.

Parameters

string $name

The name of the association property. Use null to read the current value.

Returns

$this

getProperty()

getProperty() : string

Gets the property name that should be filled with data from the target table in the source table record.

Returns

string

property()

property(string|null  $name = null) : string

Sets the property name that should be filled with data from the target table in the source table record.

If no arguments are passed, the currently configured type is returned.

Parameters

string|null $name

The name of the association property. Use null to read the current value.

Returns

string

setStrategy()

setStrategy(string  $name) : $this

Sets the strategy name to be used to fetch associated records. Keep in mind that some association types might not implement but a default strategy, rendering any changes to this setting void.

Parameters

string $name

The strategy type. Use null to read the current value.

Throws

\InvalidArgumentException

When an invalid strategy is provided.

Returns

$this

getStrategy()

getStrategy() : string

Gets the strategy name to be used to fetch associated records. Keep in mind that some association types might not implement but a default strategy, rendering any changes to this setting void.

Returns

string

strategy()

strategy(string|null  $name = null) : string

Sets the strategy name to be used to fetch associated records. Keep in mind that some association types might not implement but a default strategy, rendering any changes to this setting void.

If no arguments are passed, the currently configured strategy is returned.

Parameters

string|null $name

The strategy type. Use null to read the current value.

Throws

\InvalidArgumentException

When an invalid strategy is provided.

Returns

string

getFinder()

getFinder() : string|array

Gets the default finder to use for fetching rows from the target table.

Returns

string|array

setFinder()

setFinder(string|array  $finder) : $this

Sets the default finder to use for fetching rows from the target table.

Parameters

string|array $finder

the finder name to use or array of finder name and option.

Returns

$this

finder()

finder(string|null  $finder = null) : string|array

Sets the default finder to use for fetching rows from the target table.

If no parameters are passed, it will return the currently configured finder name.

Parameters

string|null $finder

the finder name to use

Returns

string|array

attachTo()

attachTo(\Cake\ORM\Query  $query, array  $options = array()) : void

Alters a Query object to include the associated target table data in the final result

The options array accept the following keys:

  • includeFields: Whether to include target model fields in the result or not
  • foreignKey: The name of the field to use as foreign key, if false none will be used
  • conditions: array with a list of conditions to filter the join with, this will be merged with any conditions originally configured for this association
  • fields: a list of fields in the target table to include in the result
  • type: The type of join to be used (e.g. INNER) the records found on this association
  • aliasPath: A dot separated string representing the path of association names followed from the passed query main table to this association.
  • propertyPath: A dot separated string representing the path of association properties to be followed from the passed query main entity to this association
  • joinType: The SQL join type to use in the query.
  • negateMatch: Will append a condition to the passed query for excluding matches. with this association.

Parameters

\Cake\ORM\Query $query

the query to be altered to include the target table data

array $options

Any extra options or overrides to be taken in account

Throws

\RuntimeException

if the query builder passed does not return a query object

transformRow()

transformRow(array  $row, string  $nestKey, boolean  $joined, string|null  $targetProperty = null) : array

Correctly nests a result row associated values into the correct array keys inside the source results.

Parameters

array $row

The row to transform

string $nestKey

The array key under which the results for this association should be found

boolean $joined

Whether or not the row is a result of a direct join with this association

string|null $targetProperty

The property name in the source results where the association data shuld be nested in. Will use the default one if not provided.

Returns

array

defaultRowValue()

defaultRowValue(array  $row, boolean  $joined) : array

Returns a modified row after appending a property for this association with the default empty value according to whether the association was joined or fetched externally.

Parameters

array $row

The row to set a default on.

boolean $joined

Whether or not the row is a result of a direct join with this association

Returns

array

find()

find(string|array|null  $type = null, array  $options = array()) : \Cake\ORM\Query

Proxies the finding operation to the target table's find method and modifies the query accordingly based of this association configuration

Parameters

string|array|null $type

the type of query to perform, if an array is passed, it will be interpreted as the $options parameter

array $options

The options to for the find

Returns

\Cake\ORM\Query

exists()

exists(array|callable|\Cake\Database\ExpressionInterface  $conditions) : boolean

Proxies the operation to the target table's exists method after appending the default conditions for this association

Parameters

array|callable|\Cake\Database\ExpressionInterface $conditions

The conditions to use for checking if any record matches.

Returns

boolean

updateAll()

updateAll(array  $fields, mixed  $conditions) : integer

Proxies the update operation to the target table's updateAll method

Parameters

array $fields

A hash of field => new value.

mixed $conditions

Conditions to be used, accepts anything Query::where() can take.

Returns

integer —

Count Returns the affected rows.

deleteAll()

deleteAll(mixed  $conditions) : integer

Proxies the delete operation to the target table's deleteAll method

Parameters

mixed $conditions

Conditions to be used, accepts anything Query::where() can take.

Returns

integer —

Returns the number of affected rows.

requiresKeys()

requiresKeys(array  $options = array()) : boolean

Returns true if the eager loading process will require a set of the owning table's binding keys in order to use them as a filter in the finder query.

Parameters

array $options

The options containing the strategy to be used.

Returns

boolean —

true if a list of keys will be required

__get()

__get(string  $property) : \Cake\ORM\Association

Proxies property retrieval to the target table. This is handy for getting this association's associations

Parameters

string $property

the property name

Throws

\RuntimeException

if no association with such name exists

Returns

\Cake\ORM\Association

__isset()

__isset(string  $property) : boolean

Proxies the isset call to the target table. This is handy to check if the target table has another association with the passed name

Parameters

string $property

the property name

Returns

boolean —

true if the property exists

__call()

__call(string  $method, array  $argument) : mixed

Proxies method calls to the target table.

Parameters

string $method

name of the method to be invoked

array $argument

List of arguments passed to the function

Throws

\BadMethodCallException

Returns

mixed

type()

type() : string

Get the relationship type.

Returns

string

eagerLoader()

eagerLoader(array  $options) : \Closure

Eager loads a list of records in the target table that are related to another set of records in the source table. Source records can specified in two ways: first one is by passing a Query object setup to find on the source table and the other way is by explicitly passing an array of primary key values from the source table.

The required way of passing related source records is controlled by "strategy" When the subquery strategy is used it will require a query on the source table. When using the select strategy, the list of primary keys will be used.

Returns a closure that should be run for each record returned in a specific Query. This callable will be responsible for injecting the fields that are related to each specific passed row.

Options array accepts the following keys:

  • query: Query object setup to find the source table records
  • keys: List of primary key values from the source table
  • foreignKey: The name of the field used to relate both tables
  • conditions: List of conditions to be passed to the query where() method
  • sort: The direction in which the records should be returned
  • fields: List of fields to select from the target table
  • contain: List of related tables to eager load associated to the target table
  • strategy: The name of strategy to use for finding target table records
  • nestKey: The array key under which results will be found when transforming the row

Parameters

array $options

The options for eager loading.

Returns

\Closure

cascadeDelete()

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

Handles cascading a delete from an associated model.

Each implementing class should handle the cascaded delete as required.

Parameters

\Cake\Datasource\EntityInterface $entity

The entity that started the cascaded delete.

array $options

The options for the original delete.

Returns

boolean —

Success

isOwningSide()

isOwningSide(\Cake\ORM\Table  $side) : boolean

Returns whether or not the passed table is the owning side for this association. This means that rows in the 'target' table would miss important or required information if the row in 'source' did not exist.

Parameters

\Cake\ORM\Table $side

The potential Table with ownership

Returns

boolean

saveAssociated()

saveAssociated(\Cake\Datasource\EntityInterface  $entity, array  $options = array()) : boolean|\Cake\Datasource\EntityInterface

Takes an entity from the source table and looks if there is a field matching the property name for this association. The found entity will be saved on the target table for this association by passing supplied `$options`

Parameters

\Cake\Datasource\EntityInterface $entity

an entity from the source table

array $options

options to be passed to the save method in the target table

Throws

\InvalidArgumentException

when the association data cannot be traversed.

Returns

boolean|\Cake\Datasource\EntityInterface

false if $entity could not be saved, otherwise it returns the saved entity

tableLocator()

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

Sets the table locator.

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

Parameters

\Cake\ORM\Locator\LocatorInterface|null $tableLocator

LocatorInterface instance.

Returns

\Cake\ORM\Locator\LocatorInterface

setTableLocator()

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

Sets the table locator.

Parameters

\Cake\ORM\Locator\LocatorInterface $tableLocator

LocatorInterface instance.

Returns

$this

setSaveStrategy()

setSaveStrategy(string  $strategy) : $this

Sets the strategy that should be used for saving.

Parameters

string $strategy

the strategy name to be used

Throws

\InvalidArgumentException

if an invalid strategy name is passed

Returns

$this

getSaveStrategy()

getSaveStrategy() : string

Gets the strategy that should be used for saving.

Returns

string —

the strategy to be used for saving

saveStrategy()

saveStrategy(string|null  $strategy = null) : string

Sets the strategy that should be used for saving. If called with no arguments, it will return the currently configured strategy

Parameters

string|null $strategy

the strategy name to be used

Throws

\InvalidArgumentException

if an invalid strategy name is passed

Returns

string —

the strategy to be used for saving

link()

link(\Cake\Datasource\EntityInterface  $sourceEntity, array  $targetEntities, array  $options = array()) : boolean

Associates the source entity to each of the target entities provided.

When using this method, all entities in $targetEntities will be appended to the source entity's property corresponding to this association object.

This method does not check link uniqueness. Changes are persisted in the database and also in the source entity.

Example:

$user = $users->get(1);
$allArticles = $articles->find('all')->toArray();
$users->Articles->link($user, $allArticles);

$user->get('articles') will contain all articles in $allArticles after linking

Parameters

\Cake\Datasource\EntityInterface $sourceEntity

the row belonging to the source side of this association

array $targetEntities

list of entities belonging to the target side of this association

array $options

list of options to be passed to the internal save call

Returns

boolean —

true on success, false otherwise

unlink()

unlink(\Cake\Datasource\EntityInterface  $sourceEntity, array  $targetEntities, array  $options = array()) : void

Removes all links between the passed source entity and each of the provided target entities. This method assumes that all passed objects are already persisted in the database and that each of them contain a primary key value.

Options

Additionally to the default options accepted by Table::delete(), the following keys are supported:

  • cleanProperty: Whether or not to remove all the objects in $targetEntities that are stored in $sourceEntity (default: true)

By default this method will unset each of the entity objects stored inside the source entity.

Changes are persisted in the database and also in the source entity.

Example:

$user = $users->get(1);
$user->articles = [$article1, $article2, $article3, $article4];
$users->save($user, ['Associated' => ['Articles']]);
$allArticles = [$article1, $article2, $article3];
$users->Articles->unlink($user, $allArticles);

$article->get('articles') will contain only [$article4] after deleting in the database

Parameters

\Cake\Datasource\EntityInterface $sourceEntity

an entity persisted in the source table for this association

array $targetEntities

list of entities persisted in the target table for this association

array $options

list of options to be passed to the internal delete call

Throws

\InvalidArgumentException

if non persisted entities are passed or if any of them is lacking a primary key value

replace()

replace(\Cake\Datasource\EntityInterface  $sourceEntity, array  $targetEntities, array  $options = array()) : boolean

Replaces existing association links between the source entity and the target with the ones passed. This method does a smart cleanup, links that are already persisted and present in `$targetEntities` will not be deleted, new links will be created for the passed target entities that are not already in the database and the rest will be removed.

For example, if an author has many articles, such as 'article1','article 2' and 'article 3' and you pass to this method an array containing the entities for articles 'article 1' and 'article 4', only the link for 'article 1' will be kept in database, the links for 'article 2' and 'article 3' will be deleted and the link for 'article 4' will be created.

Existing links are not deleted and created again, they are either left untouched or updated.

This method does not check link uniqueness.

On success, the passed $sourceEntity will contain $targetEntities as value in the corresponding property for this association.

Additional options for new links to be saved can be passed in the third argument, check Table::save() for information on the accepted options.

Example:

$author->articles = [$article1, $article2, $article3, $article4];
$authors->save($author);
$articles = [$article1, $article3];
$authors->getAssociation('articles')->replace($author, $articles);

$author->get('articles') will contain only [$article1, $article3] at the end

Parameters

\Cake\Datasource\EntityInterface $sourceEntity

an entity persisted in the source table for this association

array $targetEntities

list of entities from the target table to be linked

array $options

list of options to be passed to the internal save/delete calls when persisting/updating new links, or deleting existing ones

Throws

\InvalidArgumentException

if non persisted entities are passed or if any of them is lacking a primary key value

Returns

boolean —

success

setSort()

setSort(mixed  $sort) : $this

Sets the sort order in which target records should be returned.

Parameters

mixed $sort

A find() compatible order clause

Returns

$this

getSort()

getSort() : mixed

Gets the sort order in which target records should be returned.

Returns

mixed

sort()

sort(mixed  $sort = null) : mixed

Sets the sort order in which target records should be returned.

If no arguments are passed the currently configured value is returned

Parameters

mixed $sort

A find() compatible order clause

Returns

mixed

_propertyName()

_propertyName() : string

Returns default property name based on association name.

Returns

string

_options()

_options(array  $opts) : void

Parse extra options passed in the constructor.

Parameters

array $opts

original list of options passed in constructor

_appendNotMatching()

_appendNotMatching(\Cake\Datasource\QueryInterface  $query, array  $options) : void

Conditionally adds a condition to the passed Query that will make it find records where there is no match with this association.

Parameters

\Cake\Datasource\QueryInterface $query

The query to modify

array $options

Options array containing the negateMatch key.

_dispatchBeforeFind()

_dispatchBeforeFind(\Cake\ORM\Query  $query) : void

Triggers beforeFind on the target table for the query this association is attaching to

Parameters

\Cake\ORM\Query $query

the query this association is attaching itself to

_appendFields()

_appendFields(\Cake\ORM\Query  $query, \Cake\ORM\Query  $surrogate, array  $options) : void

Helper function used to conditionally append fields to the select clause of a query from the fields found in another query object.

Parameters

\Cake\ORM\Query $query

the query that will get the fields appended to

\Cake\ORM\Query $surrogate

the query having the fields to be copied from

array $options

options passed to the method attachTo

_formatAssociationResults()

_formatAssociationResults(\Cake\ORM\Query  $query, \Cake\ORM\Query  $surrogate, array  $options) : void

Adds a formatter function to the passed `$query` if the `$surrogate` query declares any other formatter. Since the `$surrogate` query correspond to the associated target table, the resulting formatter will be the result of applying the surrogate formatters to only the property corresponding to such table.

Parameters

\Cake\ORM\Query $query

the query that will get the formatter applied to

\Cake\ORM\Query $surrogate

the query having formatters for the associated target table.

array $options

options passed to the method attachTo

_bindNewAssociations()

_bindNewAssociations(\Cake\ORM\Query  $query, \Cake\ORM\Query  $surrogate, array  $options) : void

Applies all attachable associations to `$query` out of the containments found in the `$surrogate` query.

Copies all contained associations from the $surrogate query into the passed $query. Containments are altered so that they respect the associations chain from which they originated.

Parameters

\Cake\ORM\Query $query

the query that will get the associations attached to

\Cake\ORM\Query $surrogate

the query having the containments to be attached

array $options

options passed to the method attachTo

_joinCondition()

_joinCondition(array  $options) : array

Returns a single or multiple conditions to be appended to the generated join clause for getting the results on the target table.

Parameters

array $options

list of options passed to attachTo method

Throws

\RuntimeException

if the number of columns in the foreignKey do not match the number of columns in the source table primaryKey

Returns

array

_extractFinder()

_extractFinder(string|array  $finderData) : array

Helper method to infer the requested finder and its options.

Returns the inferred options from the finder $type.

Examples:

The following will call the finder 'translations' with the value of the finder as its options: $query->contain(['Comments' => ['finder' => ['translations']]]); $query->contain(['Comments' => ['finder' => ['translations' => []]]]); $query->contain(['Comments' => ['finder' => ['translations' => ['locales' => ['en_US']]]]]);

Parameters

string|array $finderData

The finder name or an array having the name as key and options as value.

Returns

array

_getClassName()

_getClassName(string  $alias, array  $options = array()) : string

Gets the table class name.

Parameters

string $alias

The alias name you want to get.

array $options

Table options array.

Returns

string

_fixtureName()

_fixtureName(string  $name) : string

Creates a fixture name

Parameters

string $name

Model class name

Returns

string —

Singular model key

_entityName()

_entityName(string  $name) : string

Creates the proper entity name (singular) for the specified name

Parameters

string $name

Name

Returns

string —

Camelized and plural model name

_modelKey()

_modelKey(string  $name) : string

Creates the proper underscored model key for associations

If the input contains a dot, assume that the right side is the real table name.

Parameters

string $name

Model class name

Returns

string —

Singular model key

_modelNameFromKey()

_modelNameFromKey(string  $key) : string

Creates the proper model name from a foreign key

Parameters

string $key

Foreign key

Returns

string —

Model name

_singularName()

_singularName(string  $name) : string

Creates the singular name for use in views.

Parameters

string $name

Name to use

Returns

string —

Variable name

_variableName()

_variableName(string  $name) : string

Creates the plural variable name for views

Parameters

string $name

Name to use

Returns

string —

Plural name for views

_singularHumanName()

_singularHumanName(string  $name) : string

Creates the singular human name used in views

Parameters

string $name

Controller name

Returns

string —

Singular human name

_camelize()

_camelize(string  $name) : string

Creates a camelized version of $name

Parameters

string $name

name

Returns

string —

Camelized name

_pluralHumanName()

_pluralHumanName(string  $name) : string

Creates the plural human name used in views

Parameters

string $name

Controller name

Returns

string —

Plural human name

_pluginPath()

_pluginPath(string  $pluginName) : string

Find the correct path for a plugin. Scans $pluginPaths for the plugin you want.

Parameters

string $pluginName

Name of the plugin you want ie. DebugKit

Returns

string —

path path to the correct plugin.

_pluginNamespace()

_pluginNamespace(string  $pluginName) : string

Return plugin's namespace

Parameters

string $pluginName

Plugin name

Returns

string —

Plugin's namespace

_saveTarget()

_saveTarget(array  $foreignKeyReference, \Cake\Datasource\EntityInterface  $parentEntity, array|\Traversable  $entities, array  $options) : boolean

Persists each of the entities into the target table and creates links between the parent entity and each one of the saved target entities.

Parameters

array $foreignKeyReference

The foreign key reference defining the link between the target entity, and the parent entity.

\Cake\Datasource\EntityInterface $parentEntity

The source entity containing the target entities to be saved.

array|\Traversable $entities

list of entities to persist in target table and to link to the parent entity

array $options

list of options accepted by Table::save().

Returns

boolean —

true on success, false otherwise.

_unlinkAssociated()

_unlinkAssociated(array  $foreignKeyReference, \Cake\Datasource\EntityInterface  $entity, \Cake\ORM\Table  $target, array  $remainingEntities = array(), array  $options = array()) : boolean

Deletes/sets null the related objects according to the dependency between source and targets and foreign key nullability Skips deleting records present in $remainingEntities

Parameters

array $foreignKeyReference

The foreign key reference defining the link between the target entity, and the parent entity.

\Cake\Datasource\EntityInterface $entity

the entity which should have its associated entities unassigned

\Cake\ORM\Table $target

The associated table

array $remainingEntities

Entities that should not be deleted

array $options

list of options accepted by Table::delete()

Returns

boolean —

success

_unlink()

_unlink(array  $foreignKey, \Cake\ORM\Table  $target, array  $conditions = array(), array  $options = array()) : boolean

Deletes/sets null the related objects matching $conditions.

The action which is taken depends on the dependency between source and targets and also on foreign key nullability

Parameters

array $foreignKey

array of foreign key properties

\Cake\ORM\Table $target

The associated table

array $conditions

The conditions that specifies what are the objects to be unlinked

array $options

list of options accepted by Table::delete()

Returns

boolean —

success

_foreignKeyAcceptsNull()

_foreignKeyAcceptsNull(\Cake\ORM\Table  $table, array  $properties) : boolean

Checks the nullable flag of the foreign key

Parameters

\Cake\ORM\Table $table

the table containing the foreign key

array $properties

the list of fields that compose the foreign key

Returns

boolean