Class BelongsTo
Represents an 1 - N relationship where the source side of the relation is related to only one record in the target table.
An example of a BelongsTo association would be Article belongs to Author.
Constants summary
-
stringMANY_TO_MANY'manyToMany' -
stringMANY_TO_ONE'manyToOne' -
stringONE_TO_MANY'oneToMany' -
stringONE_TO_ONE'oneToOne' -
stringSTRATEGY_JOIN'join' -
stringSTRATEGY_SELECT'select' -
stringSTRATEGY_SUBQUERY'subquery'
Properties summary
- $_bindingKey protected
string|string[]The field name in the owning side table that is used to match with the foreignKey
- $_cascadeCallbacks protected
boolWhether or not cascaded deletes should also fire callbacks.
- $_className protected
stringThe class name of the target table object
- $_conditions protected
array|callableA list of conditions to be always included when fetching records from the target association
- $_dependent protected
boolWhether 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.
- $_finder protected
string|arrayThe default finder name to use for fetching rows from the target table With array value, finder name and default options are allowed.
- $_foreignKey protected
string|string[]The name of the field representing the foreign key to the table to load
- $_joinType protected
stringThe type of join to be used when adding the association to a query
- $_name protected
stringName given to the association, it usually represents the alias assigned to the target associated table
- $_propertyName protected
stringThe property name that should be filled with data from the target table in the source table record.
- $_sourceTable protected
\Cake\ORM\TableSource table instance
- $_strategy protected
stringThe strategy name to be used to fetch associated records. Some association types might not implement but one strategy to fetch records.
- $_tableLocator protected
\Cake\ORM\Locator\LocatorInterfaceTable locator instance
- $_targetTable protected
\Cake\ORM\TableTarget table instance
- $_validStrategies protected
string[]Valid strategies for this type of association
Method Summary
- __construct() public
Constructor. Subclasses can override _options function to get the original list of passed options if expecting any other special key
- __get() public
Proxies property retrieval to the target table. This is handy for getting this association's associations
- __isset() public
Proxies the isset call to the target table. This is handy to check if the target table has another association with the passed name
- _appendFields() protected
Helper function used to conditionally append fields to the select clause of a query from the fields found in another query object.
- _appendNotMatching() protected
Conditionally adds a condition to the passed Query that will make it find records where there is no match with this association.
- _bindNewAssociations() protected
Applies all attachable associations to
$queryout of the containments found in the$surrogatequery. - _dispatchBeforeFind() protected
Triggers beforeFind on the target table for the query this association is attaching to
- _formatAssociationResults() protected
Adds a formatter function to the passed
$queryif the$surrogatequery declares any other formatter. Since the$surrogatequery 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. - _joinCondition() protected
Returns a single or multiple conditions to be appended to the generated join clause for getting the results on the target table.
- _options() protected
Override this function to initialize any concrete association class, it will get passed the original list of options used in the constructor
- _pluginPath() protected
Find the correct path for a plugin. Scans $pluginPaths for the plugin you want.
- attachTo() public
Alters a Query object to include the associated target table data in the final result
- bindingKey() public
Sets the name of the field representing the binding field with the target table.
- cascadeCallbacks() public
Sets whether or not cascaded deletes should also fire callbacks. If no arguments are passed, the current configured value is returned
- conditions() public
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
- defaultRowValue() public
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.
- eagerLoader() public
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.
- exists() public
Proxies the operation to the target table's exists method after appending the default conditions for this association
- find() public
Proxies the finding operation to the target table's find method and modifies the query accordingly based of this association configuration
- getBindingKey() public
Gets the name of the field representing the binding field with the target table.
- getConditions() public
Gets a list of conditions to be always included when fetching records from the target association.
- getDependent() public
Sets whether the records on the target table are dependent on the source table.
- getName() public
Gets the name for this association, usually the alias assigned to the target associated table
- getProperty() public
Gets the property name that should be filled with data from the target table in the source table record.
- getStrategy() public
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.
- isOwningSide() public
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.
- property() public
Sets the property name that should be filled with data from the target table in the source table record.
- requiresKeys() public
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.
- saveAssociated() public
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 - setBindingKey() public
Sets the name of the field representing the binding field with the target table.
- setConditions() public
Sets a list of conditions to be always included when fetching records from the target association.
- setDependent() public
Sets whether the records on the target table are dependent on the source table.
- setName() public
Sets the name for this association, usually the alias assigned to the target associated table
- setProperty() public
Sets the property name that should be filled with data from the target table in the source table record.
- setStrategy() public
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.
- source() public
Sets the table instance for the source side of the association. If no arguments are passed, the current configured table instance is returned
- strategy() public
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.
- target() public
Sets the table instance for the target side of the association. If no arguments are passed, the current configured table instance is returned
- transformRow() public
Correctly nests a result row associated values into the correct array keys inside the source results.
Method Detail
__call() public
__call(mixed $method, mixed $argument)
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
Returns
mixedThrows
BadMethodCallException__construct() public
__construct(mixed $alias, array $options)
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 optional A list of properties to be set on this object
__get() public
__get(mixed $property)
Proxies property retrieval to the target table. This is handy for getting this association's associations
Parameters
-
string$property the property name
Returns
\Cake\ORM\AssociationThrows
RuntimeExceptionif no association with such name exists
__isset() public
__isset(mixed $property)
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
booltrue if the property exists
_appendFields() protected
_appendFields(mixed $query, mixed $surrogate, mixed $options)
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
_appendNotMatching() protected
_appendNotMatching(mixed $query, mixed $options)
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
negateMatchkey.
_bindNewAssociations() protected
_bindNewAssociations(mixed $query, mixed $surrogate, mixed $options)
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
_camelize() protected
_camelize(mixed $name)
Creates a camelized version of $name
Parameters
-
string$name name
Returns
stringCamelized name
_dispatchBeforeFind() protected
_dispatchBeforeFind(mixed $query)
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
_entityName() protected
_entityName(mixed $name)
Creates the proper entity name (singular) for the specified name
Parameters
-
string$name Name
Returns
stringCamelized and plural model name
_extractFinder() protected
_extractFinder(mixed $finderData)
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_fixtureName() protected
_fixtureName(mixed $name)
Creates a fixture name
Parameters
-
string$name Model class name
Returns
stringSingular model key
_formatAssociationResults() protected
_formatAssociationResults(mixed $query, mixed $surrogate, mixed $options)
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
_getClassName() protected
_getClassName(mixed $alias, array $options)
Gets the table class name.
Parameters
-
string$alias The alias name you want to get.
-
array$options optional Table options array.
Returns
string_joinCondition() protected
_joinCondition(mixed $options)
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
Returns
\Cake\Database\Expression\IdentifierExpression[]Throws
RuntimeExceptionif the number of columns in the foreignKey do not match the number of columns in the target table primaryKey
_modelKey() protected
_modelKey(mixed $name)
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
stringSingular model key
_modelNameFromKey() protected
_modelNameFromKey(mixed $key)
Creates the proper model name from a foreign key
Parameters
-
string$key Foreign key
Returns
stringModel name
_options() protected
_options(array $options)
Override this function to initialize any concrete association class, it will get passed the original list of options used in the constructor
Parameters
-
array$options List of options used for initialization
_pluginNamespace() protected
_pluginNamespace(mixed $pluginName)
Return plugin's namespace
Parameters
-
string$pluginName Plugin name
Returns
stringPlugin's namespace
_pluginPath() protected
_pluginPath(mixed $pluginName)
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
stringpath path to the correct plugin.
_pluralHumanName() protected
_pluralHumanName(mixed $name)
Creates the plural human name used in views
Parameters
-
string$name Controller name
Returns
stringPlural human name
_propertyName() protected
_propertyName()
Returns default property name based on association name.
Returns
string_singularHumanName() protected
_singularHumanName(mixed $name)
Creates the singular human name used in views
Parameters
-
string$name Controller name
Returns
stringSingular human name
_singularName() protected
_singularName(mixed $name)
Creates the singular name for use in views.
Parameters
-
string$name Name to use
Returns
stringVariable name
_variableName() protected
_variableName(mixed $name)
Creates the plural variable name for views
Parameters
-
string$name Name to use
Returns
stringPlural name for views
attachTo() public
attachTo(\Cake\ORM\Query $query, array $options)
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 optional Any extra options or overrides to be taken in account
Throws
RuntimeExceptionif the query builder passed does not return a query object
bindingKey() public
bindingKey(mixed $key)
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 optional the table field to be used to link both tables together
Returns
string|arraycanBeJoined() public
canBeJoined(array $options)
Whether this association can be expressed directly in a query join
Parameters
-
array$options optional custom options key that could alter the return value
Returns
boolcascadeCallbacks() public
cascadeCallbacks(mixed $cascadeCallbacks)
Sets whether or not cascaded deletes should also fire callbacks. If no arguments are passed, the current configured value is returned
Parameters
-
bool|null$cascadeCallbacks optional cascade callbacks switch value
Returns
boolcascadeDelete() public
cascadeDelete(\Cake\Datasource\EntityInterface $entity, array $options)
Handle cascading deletes.
BelongsTo associations are never cleared in a cascading delete scenario.
Parameters
-
\Cake\Datasource\EntityInterface$entity The entity that started the cascaded delete.
-
array$options optional The options for the original delete.
Returns
boolSuccess.
className() public
className()
The class name of the target table object
Returns
stringconditions() public
conditions(mixed $conditions)
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 optional list of conditions to be used
Returns
array|callableSee Also
for examples on the format of the array
defaultRowValue() public
defaultRowValue(mixed $row, mixed $joined)
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.
-
bool$joined Whether or not the row is a result of a direct join with this association
Returns
arraydeleteAll() public
deleteAll(mixed $conditions)
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
intReturns the number of affected rows.
See Also
dependent() public
dependent(mixed $dependent)
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
-
bool|null$dependent optional Set the dependent mode. Use null to read the current state.
Returns
booleagerLoader() public
eagerLoader(array $options)
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
\Closureexists() public
exists(mixed $conditions)
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
boolSee Also
find() public
find(mixed $type, array $options)
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 optional the type of query to perform, if an array is passed, it will be interpreted as the
$optionsparameter-
array$options optional The options to for the find
Returns
\Cake\ORM\QuerySee Also
finder() public
finder(mixed $finder)
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 optional the finder name to use
Returns
string|arrayforeignKey() public
foreignKey(mixed $key)
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 optional the key to be used to link both tables together
Returns
string|arraygetBindingKey() public
getBindingKey()
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|string[]getCascadeCallbacks() public
getCascadeCallbacks()
Gets whether or not cascaded deletes should also fire callbacks.
Returns
boolgetClassName() public
getClassName()
Gets the class name of the target table object.
Returns
stringgetConditions() public
getConditions()
Gets a list of conditions to be always included when fetching records from the target association.
Returns
array|callableSee Also
for examples on the format of the array
getDependent() public
getDependent()
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
boolgetFinder() public
getFinder()
Gets the default finder to use for fetching rows from the target table.
Returns
string|arraygetForeignKey() public
getForeignKey()
Gets the name of the field representing the foreign key to the target table.
Returns
string|string[]getJoinType() public
getJoinType()
Gets the type of join to be used when adding the association to a query.
Returns
stringgetName() public
getName()
Gets the name for this association, usually the alias assigned to the target associated table
Returns
stringgetProperty() public
getProperty()
Gets the property name that should be filled with data from the target table in the source table record.
Returns
stringgetSource() public
getSource()
Gets the table instance for the source side of the association.
Returns
\Cake\ORM\TablegetStrategy() public
getStrategy()
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
stringgetTableLocator() public
getTableLocator()
Gets the table locator.
Returns
\Cake\ORM\Locator\LocatorInterfacegetTarget() public
getTarget()
Gets the table instance for the target side of the association.
Returns
\Cake\ORM\TableisOwningSide() public
isOwningSide(\Cake\ORM\Table $side)
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
booljoinType() public
joinType(mixed $type)
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 optional the join type to be used (e.g. INNER)
Returns
stringname() public
name(mixed $name)
Sets the name for this association.
Parameters
-
string|null$name optional Name to be assigned
Returns
stringproperty() public
property(mixed $name)
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 optional The name of the association property. Use null to read the current value.
Returns
stringrequiresKeys() public
requiresKeys(array $options)
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 optional The options containing the strategy to be used.
Returns
booltrue if a list of keys will be required
saveAssociated() public
saveAssociated(\Cake\Datasource\EntityInterface $entity, array $options)
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 optional options to be passed to the save method in the target table
Returns
\Cake\Datasource\EntityInterface|falseFalse if $entity could not be saved, otherwise it returns the saved entity
See Also
setBindingKey() public
setBindingKey(mixed $key)
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|string[]$key the table field or fields to be used to link both tables together
Returns
$thissetCascadeCallbacks() public
setCascadeCallbacks(mixed $cascadeCallbacks)
Sets whether or not cascaded deletes should also fire callbacks.
Parameters
-
bool$cascadeCallbacks cascade callbacks switch value
Returns
$thissetClassName() public
setClassName(mixed $className)
Sets the class name of the target table object.
Parameters
-
string$className Class name to set.
Returns
$thisThrows
InvalidArgumentExceptionIn case the class name is set after the target table has been resolved, and it doesn't match the target table's class name.
setConditions() public
setConditions(mixed $conditions)
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
$thisSee Also
for examples on the format of the array
setDependent() public
setDependent(mixed $dependent)
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
-
bool$dependent Set the dependent mode. Use null to read the current state.
Returns
$thissetFinder() public
setFinder(mixed $finder)
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
$thissetForeignKey() public
setForeignKey(mixed $key)
Sets the name of the field representing the foreign key to the target table.
Parameters
-
string|string[]$key the key or keys to be used to link both tables together
Returns
$thissetJoinType() public
setJoinType(mixed $type)
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
$thissetName() public
setName(mixed $name)
Sets the name for this association, usually the alias assigned to the target associated table
Parameters
-
string$name Name to be assigned
Returns
$thissetProperty() public
setProperty(mixed $name)
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
$thissetSource() public
setSource(\Cake\ORM\Table $table)
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
$thissetStrategy() public
setStrategy(mixed $name)
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.
Returns
$thisThrows
InvalidArgumentExceptionWhen an invalid strategy is provided.
setTableLocator() public
setTableLocator(\Cake\ORM\Locator\LocatorInterface $tableLocator)
Sets the table locator.
Parameters
-
\Cake\ORM\Locator\LocatorInterface$tableLocator LocatorInterface instance.
Returns
$thissetTarget() public
setTarget(\Cake\ORM\Table $table)
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
$thissource() public
source(\Cake\ORM\Table $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 optional the instance to be assigned as source side
Returns
\Cake\ORM\Tablestrategy() public
strategy(mixed $name)
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 optional The strategy type. Use null to read the current value.
Returns
stringThrows
InvalidArgumentExceptionWhen an invalid strategy is provided.
tableLocator() public
tableLocator(\Cake\ORM\Locator\LocatorInterface $tableLocator)
Sets the table locator.
If no parameters are passed, it will return the currently used locator.
Parameters
-
\Cake\ORM\Locator\LocatorInterface|null$tableLocator optional LocatorInterface instance.
Returns
\Cake\ORM\Locator\LocatorInterfacetarget() public
target(\Cake\ORM\Table $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 optional the instance to be assigned as target side
Returns
\Cake\ORM\TabletransformRow() public
transformRow(mixed $row, mixed $nestKey, mixed $joined, mixed $targetProperty)
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
-
bool$joined Whether or not the row is a result of a direct join with this association
-
string|null$targetProperty optional The property name in the source results where the association data shuld be nested in. Will use the default one if not provided.
Returns
arraytype() public
type()
Get the relationship type.
Returns
stringupdateAll() public
updateAll(mixed $fields, mixed $conditions)
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
intCount Returns the affected rows.
See Also
Property Detail
$_bindingKey protected
The field name in the owning side table that is used to match with the foreignKey
Type
string|string[]$_cascadeCallbacks protected
Whether or not cascaded deletes should also fire callbacks.
Type
bool$_className protected
The class name of the target table object
Type
string$_conditions protected
A list of conditions to be always included when fetching records from the target association
Type
array|callable$_dependent protected
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
bool$_finder protected
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$_foreignKey protected
The name of the field representing the foreign key to the table to load
Type
string|string[]$_joinType protected
The type of join to be used when adding the association to a query
Type
string$_name protected
Name given to the association, it usually represents the alias assigned to the target associated table
Type
string$_propertyName protected
The property name that should be filled with data from the target table in the source table record.
Type
string$_sourceTable protected
Source table instance
Type
\Cake\ORM\Table$_strategy protected
The strategy name to be used to fetch associated records. Some association types might not implement but one strategy to fetch records.
Type
string$_tableLocator protected
Table locator instance
Type
\Cake\ORM\Locator\LocatorInterface$_targetTable protected
Target table instance
Type
\Cake\ORM\Table$_validStrategies protected
Valid strategies for this type of association
Type
string[]
© 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/3.9/class-Cake.ORM.Association.BelongsTo.html