Target table can be inferred by its name, which is provided in the
first argument, or you can either pass the class name to be instantiated or
an instance of it directly.
The options array accept the following keys:
- className: The class name of the target table object.
- targetTable: An instance of a table object to be used as the target table.
- foreignKey: The name of the field to use as foreign key.
- targetForeignKey: The name of the field to use as the target foreign key.
- joinTable: The name of the table representing the link between the two
- through: If you choose to use an already instantiated link table, set this
key to a configured Table instance containing associations to both the source
and target tables in this association.
- dependent: Set to false, if you do not want junction table records removed
when an owning record is removed.
- cascadeCallbacks: Set to true if you want CakePHP to fire callbacks on
cascaded deletes. If false the ORM will use deleteAll() to remove data.
When true join/junction table records will be loaded and then deleted.
- conditions: array with a list of conditions to filter the join with.
- sort: The order in which results for this association should be returned.
- strategy: The strategy to be used for selecting results Either 'select'
or 'subquery'. If subquery is selected the query used to return results
in the source table will be used as conditions for getting rows in the
target table.
- saveStrategy: Either 'append' or 'replace'. Indicates the mode to be used
for saving associated entities. The former will only create new links
between both side of the relation and the latter will do a wipe and
replace to create the links between the passed entities when saving.
- strategy: The loading strategy to use. 'select' and 'subquery' are supported.
- finder: The finder method to use when loading records from this association.
Defaults to 'all'.
This method will return the association object that was built.
public belongsToMany ( string $associated, array $options = [] ) : |
||
$associated | string | the alias for the target table. This is used to uniquely identify the association |
$options | array | list of options to configure the association definition |
return |