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
-
string
MANY_TO_MANY ¶'manyToMany'
Association type for many to many associations.
-
string
MANY_TO_ONE ¶'manyToOne'
Association type for many to one associations.
-
string
ONE_TO_MANY ¶'oneToMany'
Association type for one to many associations.
-
string
ONE_TO_ONE ¶'oneToOne'
Association type for one to one associations.
-
string
STRATEGY_JOIN ¶'join'
Strategy name to use joins for fetching associated records
-
string
STRATEGY_SELECT ¶'select'
Strategy name to use a select for fetching associated records
-
string
STRATEGY_SUBQUERY ¶'subquery'
Strategy name to use a subquery for fetching associated records
Property Summary
-
$_bindingKey protected
array<string>|string
The field name in the owning side table that is used to match with the foreignKey
-
$_cascadeCallbacks protected
bool
Whether cascaded deletes should also fire callbacks.
-
$_className protected
string
The class name of the target table object
-
$_conditions protected
Closure|array
A list of conditions to be always included when fetching records from the target association
-
$_dependent protected
bool
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.
-
$_finder protected
array|string
The default finder name to use for fetching rows from the target table With array value, finder name and default options are allowed.
-
$_foreignKey protected
array<string>|string|false
The name of the field representing the foreign key to the table to load
-
$_joinType protected
string
The type of join to be used when adding the association to a query
-
$_name protected
string
Name given to the association, it usually represents the alias assigned to the target associated table
-
$_propertyName protected
string
The property name that should be filled with data from the target table in the source table record.
-
$_sourceTable protected
Cake\ORM\Table
Source table instance
-
$_strategy protected
string
The 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\LocatorInterface|null
Table locator instance
-
$_targetTable protected
Cake\ORM\Table
Target table instance
-
$_validStrategies protected
array<string>
Valid strategies for this type of association
-
$defaultTable protected
string|null
This object's default table alias.
Method Summary
-
__call() public
Proxies method calls to the target table.
-
__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
$query
out of the containments found in the$surrogate
query. -
_camelize() protected
Creates a camelized version of $name
-
_dispatchBeforeFind() protected
Triggers beforeFind on the target table for the query this association is attaching to
-
_entityName() protected
Creates the proper entity name (singular) for the specified name
-
_extractFinder() protected
Helper method to infer the requested finder and its options.
-
_fixtureName() protected
Creates a fixture name
-
_formatAssociationResults() protected
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. -
_joinCondition() protected
Returns a single or multiple conditions to be appended to the generated join clause for getting the results on the target table.
-
_modelKey() protected
Creates the proper underscored model key for associations
-
_modelNameFromKey() protected
Creates the proper model name from a foreign key
-
_options() protected
Override this function to initialize any concrete association class, it will get passed the original list of options used in the constructor
-
_pluginNamespace() protected
Return plugin's namespace
-
_pluginPath() protected
Find the correct path for a plugin. Scans $pluginPaths for the plugin you want.
-
_pluralHumanName() protected
Creates the plural human name used in views
-
_propertyName() protected
Returns default property name based on association name.
-
_singularHumanName() protected
Creates the singular human name used in views
-
_singularName() protected
Creates the singular name for use in views.
-
_variableName() protected
Creates the plural variable name for views
-
attachTo() public
Alters a Query object to include the associated target table data in the final result
-
canBeJoined() public
Whether this association can be expressed directly in a query join
-
cascadeDelete() public
Handle cascading deletes.
-
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.
-
deleteAll() public
Proxies the delete operation to the target
Table::deleteAll()
method -
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 be 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
-
fetchTable() public
Convenience method to get a table instance.
-
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. When not manually specified the primary key of the owning side table is used.
-
getCascadeCallbacks() public
Gets whether cascaded deletes should also fire callbacks.
-
getClassName() public
Gets the class name of the target table object.
-
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.
-
getFinder() public
Gets the default finder to use for fetching rows from the target table.
-
getForeignKey() public
Gets the name of the field representing the foreign key to the target table.
-
getJoinType() public
Gets the type of join to be used when adding the association to a query.
-
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.
-
getSource() public
Gets the table instance for the source side of the association.
-
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.
-
getTableLocator() public
Gets the table locator.
-
getTarget() public
Gets the table instance for the target side of the association.
-
isOwningSide() public
Returns whether 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.
-
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. When not manually specified the primary key of the owning side table is used.
-
setCascadeCallbacks() public
Sets whether cascaded deletes should also fire callbacks.
-
setClassName() public
Sets the class name of the target table object.
-
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.
-
setFinder() public
Sets the default finder to use for fetching rows from the target table.
-
setForeignKey() public
Sets the name of the field representing the foreign key to the target table.
-
setJoinType() public
Sets the type of join to be used when adding the association to a query.
-
setProperty() public
Sets the property name that should be filled with data from the target table in the source table record.
-
setSource() public
Sets the table instance for the source side of the association.
-
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.
-
setTableLocator() public
Sets the table locator.
-
setTarget() public
Sets the table instance for the target side of the association.
-
transformRow() public
Correctly nests a result row associated values into the correct array keys inside the source results.
-
type() public
Get the relationship type.
-
updateAll() public
Proxies the update operation to the target
Table::updateAll()
method
Method Detail
__call() ¶ public
__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
Returns
mixed
Throws
BadMethodCallException
__construct() ¶ public
__construct(string $alias, array<string, mixed> $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<string, mixed>
$options optional A list of properties to be set on this object
__get() ¶ public
__get(string $property): self
Proxies property retrieval to the target table. This is handy for getting this association's associations
Parameters
-
string
$property the property name
Returns
self
Throws
RuntimeException
if no association with such name exists
__isset() ¶ public
__isset(string $property): bool
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
bool
_appendFields() ¶ protected
_appendFields(Cake\ORM\Query\SelectQuery $query, Cake\ORM\Query\SelectQuery $surrogate, array<string, mixed> $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\SelectQuery
$query the query that will get the fields appended to
-
Cake\ORM\Query\SelectQuery
$surrogate the query having the fields to be copied from
-
array<string, mixed>
$options options passed to the method
attachTo
Returns
void
_appendNotMatching() ¶ protected
_appendNotMatching(Cake\ORM\Query\SelectQuery $query, array<string, mixed> $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\ORM\Query\SelectQuery
$query The query to modify
-
array<string, mixed>
$options Options array containing the
negateMatch
key.
Returns
void
_bindNewAssociations() ¶ protected
_bindNewAssociations(Cake\ORM\Query\SelectQuery $query, Cake\ORM\Query\SelectQuery $surrogate, array<string, mixed> $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\SelectQuery
$query the query that will get the associations attached to
-
Cake\ORM\Query\SelectQuery
$surrogate the query having the containments to be attached
-
array<string, mixed>
$options options passed to the method
attachTo
Returns
void
_camelize() ¶ protected
_camelize(string $name): string
Creates a camelized version of $name
Parameters
-
string
$name name
Returns
string
_dispatchBeforeFind() ¶ protected
_dispatchBeforeFind(Cake\ORM\Query\SelectQuery $query): void
Triggers beforeFind on the target table for the query this association is attaching to
Parameters
-
Cake\ORM\Query\SelectQuery
$query the query this association is attaching itself to
Returns
void
_entityName() ¶ protected
_entityName(string $name): string
Creates the proper entity name (singular) for the specified name
Parameters
-
string
$name Name
Returns
string
_extractFinder() ¶ protected
_extractFinder(array|string $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
-
array|string
$finderData The finder name or an array having the name as key and options as value.
Returns
array
_fixtureName() ¶ protected
_fixtureName(string $name): string
Creates a fixture name
Parameters
-
string
$name Model class name
Returns
string
_formatAssociationResults() ¶ protected
_formatAssociationResults(Cake\ORM\Query\SelectQuery $query, Cake\ORM\Query\SelectQuery $surrogate, array<string, mixed> $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\SelectQuery
$query the query that will get the formatter applied to
-
Cake\ORM\Query\SelectQuery
$surrogate the query having formatters for the associated target table.
-
array<string, mixed>
$options options passed to the method
attachTo
Returns
void
_joinCondition() ¶ protected
_joinCondition(array<string, mixed> $options): arrayCake\Database\Expression\IdentifierExpression>
Returns a single or multiple conditions to be appended to the generated join clause for getting the results on the target table.
Parameters
-
array<string, mixed>
$options list of options passed to attachTo method
Returns
arrayCake\Database\Expression\IdentifierExpression>
Throws
Cake\Database\Exception\DatabaseException
if the number of columns in the foreignKey do not match the number of columns in the target table primaryKey
_modelKey() ¶ protected
_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
_modelNameFromKey() ¶ protected
_modelNameFromKey(string $key): string
Creates the proper model name from a foreign key
Parameters
-
string
$key Foreign key
Returns
string
_options() ¶ protected
_options(array<string, mixed> $options): void
Override this function to initialize any concrete association class, it will get passed the original list of options used in the constructor
Parameters
-
array<string, mixed>
$options List of options used for initialization
Returns
void
_pluginNamespace() ¶ protected
_pluginNamespace(string $pluginName): string
Return plugin's namespace
Parameters
-
string
$pluginName Plugin name
Returns
string
_pluginPath() ¶ protected
_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
_pluralHumanName() ¶ protected
_pluralHumanName(string $name): string
Creates the plural human name used in views
Parameters
-
string
$name Controller name
Returns
string
_propertyName() ¶ protected
_propertyName(): string
Returns default property name based on association name.
Returns
string
_singularHumanName() ¶ protected
_singularHumanName(string $name): string
Creates the singular human name used in views
Parameters
-
string
$name Controller name
Returns
string
_singularName() ¶ protected
_singularName(string $name): string
Creates the singular name for use in views.
Parameters
-
string
$name Name to use
Returns
string
_variableName() ¶ protected
_variableName(string $name): string
Creates the plural variable name for views
Parameters
-
string
$name Name to use
Returns
string
attachTo() ¶ public
attachTo(Cake\ORM\Query\SelectQuery $query, array<string, mixed> $options = []): 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
- 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\SelectQuery
$query the query to be altered to include the target table data
-
array<string, mixed>
$options optional Any extra options or overrides to be taken in account
Returns
void
Throws
RuntimeException
Unable to build the query or associations.
canBeJoined() ¶ public
canBeJoined(array<string, mixed> $options = []): bool
Whether this association can be expressed directly in a query join
Parameters
-
array<string, mixed>
$options optional custom options key that could alter the return value
Returns
bool
cascadeDelete() ¶ public
cascadeDelete(Cake\Datasource\EntityInterface $entity, array<string, mixed> $options = []): bool
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<string, mixed>
$options optional The options for the original delete.
Returns
bool
defaultRowValue() ¶ public
defaultRowValue(array<string, mixed> $row, bool $joined): array<string, mixed>
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<string, mixed>
$row The row to set a default on.
-
bool
$joined Whether the row is a result of a direct join with this association
Returns
array<string, mixed>
deleteAll() ¶ public
deleteAll(Cake\Database\Expression\QueryExpressionClosure|array|string|null $conditions): int
Proxies the delete operation to the target Table::deleteAll()
method
Parameters
-
Cake\Database\Expression\QueryExpressionClosure|array|string|null
$conditions Conditions to be used, accepts anything Query::where() can take.
Returns
int
See Also
eagerLoader() ¶ public
eagerLoader(array<string, mixed> $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 be 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: SelectQuery 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<string, mixed>
$options
Returns
Closure
exists() ¶ public
exists(Cake\Database\ExpressionInterfaceClosure|array|string|null $conditions): bool
Proxies the operation to the target table's exists method after appending the default conditions for this association
Parameters
-
Cake\Database\ExpressionInterfaceClosure|array|string|null
$conditions The conditions to use for checking if any record matches.
Returns
bool
See Also
fetchTable() ¶ public
fetchTable(string|null $alias = null, array<string, mixed> $options = []): Cake\ORM\Table
Convenience method to get a table instance.
Parameters
-
string|null
$alias optional The alias name you want to get. Should be in CamelCase format. If
null
then the value of $defaultTable property is used.-
array<string, mixed>
$options optional The options you want to build the table with. If a table has already been loaded the registry options will be ignored.
Returns
Cake\ORM\Table
Throws
Cake\Core\Exception\CakeException
If `$alias` argument and `$defaultTable` property both are `null`.
See Also
find() ¶ public
find(array<string, mixed>|string|null $type = null, mixed ...$args): Cake\ORM\Query\SelectQuery
Proxies the finding operation to the target table's find method and modifies the query accordingly based of this association configuration
Parameters
-
array<string, mixed>|string|null
$type optional the type of query to perform, if an array is passed, it will be interpreted as the
$args
parameter-
mixed
...$args Arguments that match up to finder-specific parameters
Returns
Cake\ORM\Query\SelectQuery
See Also
getBindingKey() ¶ public
getBindingKey(): array<string>|string
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
array<string>|string
getCascadeCallbacks() ¶ public
getCascadeCallbacks(): bool
Gets whether cascaded deletes should also fire callbacks.
Returns
bool
getClassName() ¶ public
getClassName(): string
Gets the class name of the target table object.
Returns
string
getConditions() ¶ public
getConditions(): Closure|array
Gets a list of conditions to be always included when fetching records from the target association.
Returns
Closure|array
See Also
getDependent() ¶ public
getDependent(): bool
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
bool
getFinder() ¶ public
getFinder(): array|string
Gets the default finder to use for fetching rows from the target table.
Returns
array|string
getForeignKey() ¶ public
getForeignKey(): array<string>|string|false
Gets the name of the field representing the foreign key to the target table.
Returns
array<string>|string|false
getJoinType() ¶ public
getJoinType(): string
Gets the type of join to be used when adding the association to a query.
Returns
string
getName() ¶ public
getName(): string
Gets the name for this association, usually the alias assigned to the target associated table
Returns
string
getProperty() ¶ public
getProperty(): string
Gets the property name that should be filled with data from the target table in the source table record.
Returns
string
getSource() ¶ public
getSource(): Cake\ORM\Table
Gets the table instance for the source side of the association.
Returns
Cake\ORM\Table
getStrategy() ¶ public
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
getTableLocator() ¶ public
getTableLocator(): Cake\ORM\Locator\LocatorInterface
Gets the table locator.
Returns
Cake\ORM\Locator\LocatorInterface
getTarget() ¶ public
getTarget(): Cake\ORM\Table
Gets the table instance for the target side of the association.
Returns
Cake\ORM\Table
isOwningSide() ¶ public
isOwningSide(Cake\ORM\Table $side): bool
Returns whether 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
bool
requiresKeys() ¶ public
requiresKeys(array<string, mixed> $options = []): bool
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<string, mixed>
$options optional The options containing the strategy to be used.
Returns
bool
saveAssociated() ¶ public
saveAssociated(Cake\Datasource\EntityInterface $entity, array<string, mixed> $options = []): Cake\Datasource\EntityInterface|false
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<string, mixed>
$options optional options to be passed to the save method in the target table
Returns
Cake\Datasource\EntityInterface|false
See Also
setBindingKey() ¶ public
setBindingKey(array<string>|string $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
-
array<string>|string
$key the table field or fields to be used to link both tables together
Returns
$this
setCascadeCallbacks() ¶ public
setCascadeCallbacks(bool $cascadeCallbacks): $this
Sets whether cascaded deletes should also fire callbacks.
Parameters
-
bool
$cascadeCallbacks cascade callbacks switch value
Returns
$this
setClassName() ¶ public
setClassName(string $className): $this
Sets the class name of the target table object.
Parameters
-
string
$className Class name to set.
Returns
$this
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.
setConditions() ¶ public
setConditions(Closure|array $conditions): $this
Sets a list of conditions to be always included when fetching records from the target association.
Parameters
-
Closure|array
$conditions list of conditions to be used
Returns
$this
See Also
setDependent() ¶ public
setDependent(bool $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
-
bool
$dependent Set the dependent mode. Use null to read the current state.
Returns
$this
setFinder() ¶ public
setFinder(array|string $finder): $this
Sets the default finder to use for fetching rows from the target table.
Parameters
-
array|string
$finder the finder name to use or array of finder name and option.
Returns
$this
setForeignKey() ¶ public
setForeignKey(array<string>|string|false $key): $this
Sets the name of the field representing the foreign key to the target table.
Parameters
-
array<string>|string|false
$key the key or keys to be used to link both tables together, if set to
false
no join conditions will be generated automatically.
Returns
$this
setJoinType() ¶ public
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
setProperty() ¶ public
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
setSource() ¶ public
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
setStrategy() ¶ public
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.
Returns
$this
Throws
InvalidArgumentException
When an invalid strategy is provided.
setTableLocator() ¶ public
setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $this
Sets the table locator.
Parameters
-
Cake\ORM\Locator\LocatorInterface
$tableLocator LocatorInterface instance.
Returns
$this
setTarget() ¶ public
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
transformRow() ¶ public
transformRow(array<string, mixed> $row, string $nestKey, bool $joined, string|null $targetProperty = null): array
Correctly nests a result row associated values into the correct array keys inside the source results.
Parameters
-
array<string, mixed>
$row The row to transform
-
string
$nestKey The array key under which the results for this association should be found
-
bool
$joined Whether 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
array
updateAll() ¶ public
updateAll(Cake\Database\Expression\QueryExpressionClosure|array|string $fields, Cake\Database\Expression\QueryExpressionClosure|array|string|null $conditions): int
Proxies the update operation to the target Table::updateAll()
method
Parameters
-
Cake\Database\Expression\QueryExpressionClosure|array|string
$fields A hash of field => new value.
-
Cake\Database\Expression\QueryExpressionClosure|array|string|null
$conditions Conditions to be used, accepts anything Query::where()
Returns
int
See Also
Property Detail
$_bindingKey ¶ protected
The field name in the owning side table that is used to match with the foreignKey
Type
array<string>|string
$_conditions ¶ protected
A list of conditions to be always included when fetching records from the target association
Type
Closure|array
$_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
array|string
$_foreignKey ¶ protected
The name of the field representing the foreign key to the table to load
Type
array<string>|string|false
$_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
$_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