STRATEGY_JOIN
STRATEGY_JOIN = 'join' : string
Strategy name to use joins for fetching associated records
Represents an 1 - 1 relationship where the source side of the relation is related to only one record in the target table and vice versa.
An example of a HasOne association would be User has one Profile.
$_sourceTable : \Cake\ORM\Table
Source table instance
$_targetTable : \Cake\ORM\Table
Target table instance
$_tableLocator : \Cake\ORM\Locator\LocatorInterface
Table locator instance
__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
string | $alias | The name given to the association |
array | $options | A list of properties to be set on this object |
setCascadeCallbacks(boolean $cascadeCallbacks) : $this
Sets whether or not cascaded deletes should also fire callbacks.
boolean | $cascadeCallbacks | cascade callbacks switch value |
None found |
getCascadeCallbacks() : boolean
Gets whether or not cascaded deletes should also fire callbacks.
None found |
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
boolean|null | $cascadeCallbacks | cascade callbacks switch value |
None found |
setClassName(string $className) : $this
Sets the class name of the target table object.
string | $className | Class name to set. |
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.
None found |
getClassName() : string
Gets the class name of the target table object.
None found |
None found |
setSource(\Cake\ORM\Table $table) : $this
Sets the table instance for the source side of the association.
\Cake\ORM\Table | $table | the instance to be assigned as source side |
None found |
getSource() : \Cake\ORM\Table
Gets the table instance for the source side of the association.
None found |
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
\Cake\ORM\Table|null | $table | the instance to be assigned as source side |
None found |
setTarget(\Cake\ORM\Table $table) : $this
Sets the table instance for the target side of the association.
\Cake\ORM\Table | $table | the instance to be assigned as target side |
None found |
getTarget() : \Cake\ORM\Table
Gets the table instance for the target side of the association.
None found |
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
\Cake\ORM\Table|null | $table | the instance to be assigned as target side |
None found |
setConditions(array|callable $conditions) : $this
Sets a list of conditions to be always included when fetching records from the target association.
array|callable | $conditions | list of conditions to be used |
None found |
getConditions() : array|callable
Gets a list of conditions to be always included when fetching records from the target association.
None found |
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
array|null | $conditions | list of conditions to be used |
None found |
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.
string|array | $key | the table field or fields to be used to link both tables together |
None found |
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.
None found |
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
string|null | $key | the table field to be used to link both tables together |
None found |
getForeignKey() : string
Gets the name of the field representing the foreign key to the target table.
None found |
setForeignKey(string|array $key) : $this
Sets the name of the field representing the foreign key to the target table.
string|array | $key | the key or keys to be used to link both tables together |
None found |
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
string|null | $key | the key to be used to link both tables together |
None found |
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.
boolean | $dependent | Set the dependent mode. Use null to read the current state. |
None found |
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.
None found |
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.
boolean|null | $dependent | Set the dependent mode. Use null to read the current state. |
None found |
canBeJoined(array $options = array()) : boolean
Whether this association can be expressed directly in a query join
array | $options | custom options key that could alter the return value |
None found |
setJoinType(string $type) : $this
Sets the type of join to be used when adding the association to a query.
string | $type | the join type to be used (e.g. INNER) |
None found |
getJoinType() : string
Gets the type of join to be used when adding the association to a query.
None found |
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.
string|null | $type | the join type to be used (e.g. INNER) |
None found |
setProperty(string $name) : $this
Sets the property name that should be filled with data from the target table in the source table record.
string | $name | The name of the association property. Use null to read the current value. |
None found |
getProperty() : string
Gets the property name that should be filled with data from the target table in the source table record.
None found |
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.
string|null | $name | The name of the association property. Use null to read the current value. |
None found |
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.
string | $name | The strategy type. Use null to read the current value. |
When an invalid strategy is provided.
None found |
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.
None found |
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.
string|null | $name | The strategy type. Use null to read the current value. |
When an invalid strategy is provided.
None found |
getFinder() : string|array
Gets the default finder to use for fetching rows from the target table.
None found |
setFinder(string|array $finder) : $this
Sets the default finder to use for fetching rows from the target table.
string|array | $finder | the finder name to use or array of finder name and option. |
None found |
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.
string|null | $finder | the finder name to use |
None found |
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:
\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 |
if the query builder passed does not return a query object
None found |
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.
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. |
None found |
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.
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 |
None found |
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
string|array|null | $type | the type of query to perform, if an array is passed,
it will be interpreted as the |
array | $options | The options to for the find |
None found |
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
array|callable|\Cake\Database\ExpressionInterface | $conditions | The conditions to use for checking if any record matches. |
None found |
updateAll(array $fields, mixed $conditions) : integer
Proxies the update operation to the target table's updateAll method
array | $fields | A hash of field => new value. |
mixed | $conditions | Conditions to be used, accepts anything Query::where() can take. |
Count Returns the affected rows.
None found |
deleteAll(mixed $conditions) : integer
Proxies the delete operation to the target table's deleteAll method
mixed | $conditions | Conditions to be used, accepts anything Query::where() can take. |
Returns the number of affected rows.
None found |
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.
array | $options | The options containing the strategy to be used. |
true if a list of keys will be required
None found |
__get(string $property) : \Cake\ORM\Association
Proxies property retrieval to the target table. This is handy for getting this association's associations
string | $property | the property name |
if no association with such name exists
None found |
__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
string | $property | the property name |
true if the property exists
None found |
__call(string $method, array $argument) : mixed
Proxies method calls to the target table.
string | $method | name of the method to be invoked |
array | $argument | List of arguments passed to the function |
None found |
None found |
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:
array | $options | The options for eager loading. |
None found |
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.
\Cake\Datasource\EntityInterface | $entity | The entity that started the cascaded delete. |
array | $options | The options for the original delete. |
Success
None found |
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.
\Cake\ORM\Table | $side | The potential Table with ownership |
None found |
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`
\Cake\Datasource\EntityInterface | $entity | an entity from the source table |
array | $options | options to be passed to the save method in the target table |
false if $entity could not be saved, otherwise it returns the saved entity
None found |
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.
\Cake\ORM\Locator\LocatorInterface|null | $tableLocator | LocatorInterface instance. |
None found |
setTableLocator(\Cake\ORM\Locator\LocatorInterface $tableLocator) : $this
Sets the table locator.
\Cake\ORM\Locator\LocatorInterface | $tableLocator | LocatorInterface instance. |
None found |
getTableLocator() : \Cake\ORM\Locator\LocatorInterface
Gets the table locator.
None found |
_propertyName() : string
Returns default property name based on association name.
None found |
_options(array $options) : void
Override this function to initialize any concrete association class, it will get passed the original list of options used in the constructor
array | $options | List of options used for initialization |
None found |
_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.
\Cake\Datasource\QueryInterface | $query | The query to modify |
array | $options | Options array containing the |
None found |
_dispatchBeforeFind(\Cake\ORM\Query $query) : void
Triggers beforeFind on the target table for the query this association is attaching to
\Cake\ORM\Query | $query | the query this association is attaching itself to |
None found |
_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.
\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 |
None found |
_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.
\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 |
None found |
_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.
\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 |
None found |
_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.
array | $options | list of options passed to attachTo method |
if the number of columns in the foreignKey do not match the number of columns in the source table primaryKey
None found |
_extractFinder(string|array $finderData) : array
Helper method to infer the requested finder and its options.
Returns the inferred options from the finder $type.
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']]]]]);
string|array | $finderData | The finder name or an array having the name as key and options as value. |
None found |
_getClassName(string $alias, array $options = array()) : string
Gets the table class name.
string | $alias | The alias name you want to get. |
array | $options | Table options array. |
None found |
_fixtureName(string $name) : string
Creates a fixture name
string | $name | Model class name |
Singular model key
None found |
_entityName(string $name) : string
Creates the proper entity name (singular) for the specified name
string | $name | Name |
Camelized and plural model name
None found |
_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.
string | $name | Model class name |
Singular model key
None found |
_modelNameFromKey(string $key) : string
Creates the proper model name from a foreign key
string | $key | Foreign key |
Model name
None found |
_singularName(string $name) : string
Creates the singular name for use in views.
string | $name | Name to use |
Variable name
None found |
_variableName(string $name) : string
Creates the plural variable name for views
string | $name | Name to use |
Plural name for views
None found |
_singularHumanName(string $name) : string
Creates the singular human name used in views
string | $name | Controller name |
Singular human name
None found |
_camelize(string $name) : string
Creates a camelized version of $name
string | $name | name |
Camelized name
None found |
_pluralHumanName(string $name) : string
Creates the plural human name used in views
string | $name | Controller name |
Plural human name
None found |
_pluginPath(string $pluginName) : string
Find the correct path for a plugin. Scans $pluginPaths for the plugin you want.
string | $pluginName | Name of the plugin you want ie. DebugKit |
path path to the correct plugin.
None found |
_pluginNamespace(string $pluginName) : string
Return plugin's namespace
string | $pluginName | Plugin name |
Plugin's namespace
None found |