PHP 클래스 Cake\ORM\Association\BelongsToMany

An example of a BelongsToMany association would be Article belongs to many Tags.
상속: extends Cake\ORM\Association, use trait Cake\ORM\Association\ExternalAssociationTrait
파일 보기 프로젝트 열기: cakephp/orm 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_dependent boolean Defaults to true for backwards compatibility.
$_joinType string The type of join to be used when adding the association to a query
$_junctionAssociationName string The name of the hasMany association from the target table to the junction table
$_junctionConditions null | array Filtered conditions that reference the junction table.
$_junctionProperty string The name of the property to be set containing data from the junction table once a record from the target table is hydrated
$_junctionTable Cake\ORM\Table Junction table instance
$_junctionTableName string Junction table name
$_saveStrategy string Saving strategy to be used by this association
$_strategy string The strategy name to be used to fetch associated records.
$_targetConditions null | array Filtered conditions that reference the target table.
$_targetForeignKey string | array The name of the field representing the foreign key to the target table
$_through string | Cake\ORM\Table The table instance for the junction relation.
$_validStrategies array Valid strategies for this type of association

공개 메소드들

메소드 설명
_buildBaseQuery ( )
_externalOptions ( )
attachTo ( Query $query, array $options = [] ) : void Alters a Query object to include the associated target table data in the final result
cascadeDelete ( Cake\Datasource\EntityInterface $entity, array $options = [] ) : boolean Clear out the data in the junction table for a given entity.
conditions ( $conditions = null ) {@inheritDoc}
find ( string | array | null $type = null, array $options = [] ) : Query Proxies the finding operation to the target table's find method and modifies the query accordingly based of this association configuration.
isOwningSide ( Table $side ) : boolean Returns boolean true, as both of the tables 'own' rows in the other side of the association via the joint table.
junction ( string | Table | null $table = null ) : Table Sets the table instance for the junction relation. If no arguments are passed, the current configured table instance is returned
link ( Cake\Datasource\EntityInterface $sourceEntity, array $targetEntities, array $options = [] ) : boolean Associates the source entity to each of the target entities provided by creating links in the junction table. Both the source entity and each of the target entities are assumed to be already persisted, if they are marked as new or their status is unknown then an exception will be thrown.
replaceLinks ( Cake\Datasource\EntityInterface $sourceEntity, array $targetEntities, array $options = [] ) : 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.
saveAssociated ( Cake\Datasource\EntityInterface $entity, array $options = [] ) : 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
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
targetForeignKey ( string | null $key = null ) : string Sets the name of the field representing the foreign key to the target table.
type ( ) : string Get the relationship type.
unlink ( Cake\Datasource\EntityInterface $sourceEntity, array $targetEntities, array | boolean $options = [] ) : boolean 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.

보호된 메소드들

메소드 설명
_appendJunctionJoin ( Query $query, string | array $conditions ) : Query Append a join to the junction table.
_appendNotMatching ( $query, $options ) {@inheritDoc}
_buildQuery ( array $options ) : Query Auxiliary function to construct a new Query object to return all the records in the target table that are associated to those specified in $options from the source table.
_buildResultMap ( Query $fetchQuery, array $options ) : array Builds an array containing the results from fetchQuery indexed by the foreignKey value corresponding to this association.
_checkPersistenceStatus ( Cake\Datasource\EntityInterface $sourceEntity, array $targetEntities ) : boolean Throws an exception should any of the passed entities is not persisted.
_collectJointEntities ( Cake\Datasource\EntityInterface $sourceEntity, array $targetEntities ) : array Returns the list of joint entities that exist between the source entity and each of the passed target entities
_diffLinks ( Query $existing, array $jointEntities, array $targetEntities, array $options = [] ) : array Helper method used to delete the difference between the links passed in $existing and $jointEntities. This method will return the values from $targetEntities that were not deleted from calculating the difference.
_generateJunctionAssociations ( Table $junction, Table $source, Table $target ) : void Generate associations on the junction table as necessary
_generateSourceAssociations ( Table $junction, Table $source ) : void Generate additional source table associations as necessary.
_generateTargetAssociations ( Table $junction, Table $source, Table $target ) : void Generate reciprocal associations as necessary.
_joinCondition ( array $options ) : boolean Return false as join conditions are defined in the junction table
_junctionAssociationName ( ) : string Returns the name of the association from the target table to the junction table, this name is used to generate alias in the query and to later on retrieve the results.
_junctionTableName ( string | null $name = null ) : string Sets the name of the junction table.
_linkField ( array $options ) : string Generates a string used as a table field that contains the values upon which the filter should be applied
_options ( array $opts ) : void Parse extra options passed in the constructor.
_saveLinks ( Cake\Datasource\EntityInterface $sourceEntity, array $targetEntities, array $options ) : boolean Creates links between the source entity and each of the passed target entities
_saveTarget ( Cake\Datasource\EntityInterface $parentEntity, array | Traversable $entities, array $options ) : Cake\Datasource\EntityInterface | 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.
junctionConditions ( ) : array Returns filtered conditions that specifically reference the junction table.
targetConditions ( ) : mixed Returns filtered conditions that reference the target table.

메소드 상세

_appendJunctionJoin() 보호된 메소드

Append a join to the junction table.
protected _appendJunctionJoin ( Query $query, string | array $conditions ) : Query
$query Cake\ORM\Query The query to append.
$conditions string | array The query conditions to use.
리턴 Cake\ORM\Query The modified query.

_appendNotMatching() 보호된 메소드

{@inheritDoc}
protected _appendNotMatching ( $query, $options )

_buildBaseQuery() 공개 메소드

public _buildBaseQuery ( )

_buildQuery() 보호된 메소드

This is used for eager loading records on the target table based on conditions.
protected _buildQuery ( array $options ) : Query
$options array options accepted by eagerLoader()
리턴 Cake\ORM\Query

_buildResultMap() 보호된 메소드

Builds an array containing the results from fetchQuery indexed by the foreignKey value corresponding to this association.
protected _buildResultMap ( Query $fetchQuery, array $options ) : array
$fetchQuery Cake\ORM\Query The query to get results from
$options array The options passed to the eager loader
리턴 array

_checkPersistenceStatus() 보호된 메소드

Throws an exception should any of the passed entities is not persisted.
protected _checkPersistenceStatus ( Cake\Datasource\EntityInterface $sourceEntity, array $targetEntities ) : boolean
$sourceEntity Cake\Datasource\EntityInterface the row belonging to the `source` side of this association
$targetEntities array list of entities belonging to the `target` side of this association
리턴 boolean

_collectJointEntities() 보호된 메소드

Returns the list of joint entities that exist between the source entity and each of the passed target entities
protected _collectJointEntities ( Cake\Datasource\EntityInterface $sourceEntity, array $targetEntities ) : array
$sourceEntity Cake\Datasource\EntityInterface The row belonging to the source side of this association.
$targetEntities array The rows belonging to the target side of this association.
리턴 array

_externalOptions() 공개 메소드

public _externalOptions ( )

_generateJunctionAssociations() 보호된 메소드

Generates the following associations: - junction belongsTo source e.g. ArticlesTags belongsTo Tags - junction belongsTo target e.g. ArticlesTags belongsTo Articles You can override these generated associations by defining associations with the correct aliases.
protected _generateJunctionAssociations ( Table $junction, Table $source, Table $target ) : void
$junction Cake\ORM\Table The junction table.
$source Cake\ORM\Table The source table.
$target Cake\ORM\Table The target table.
리턴 void

_generateSourceAssociations() 보호된 메소드

Generates the following associations: - source hasMany junction e.g. Tags hasMany ArticlesTags You can override these generated associations by defining associations with the correct aliases.
protected _generateSourceAssociations ( Table $junction, Table $source ) : void
$junction Cake\ORM\Table The junction table.
$source Cake\ORM\Table The source table.
리턴 void

_generateTargetAssociations() 보호된 메소드

Generates the following associations: - target hasMany junction e.g. Articles hasMany ArticlesTags - target belongsToMany source e.g Articles belongsToMany Tags. You can override these generated associations by defining associations with the correct aliases.
protected _generateTargetAssociations ( Table $junction, Table $source, Table $target ) : void
$junction Cake\ORM\Table The junction table.
$source Cake\ORM\Table The source table.
$target Cake\ORM\Table The target table.
리턴 void

_joinCondition() 보호된 메소드

Return false as join conditions are defined in the junction table
protected _joinCondition ( array $options ) : boolean
$options array list of options passed to attachTo method
리턴 boolean false

_junctionAssociationName() 보호된 메소드

Returns the name of the association from the target table to the junction table, this name is used to generate alias in the query and to later on retrieve the results.
protected _junctionAssociationName ( ) : string
리턴 string

_junctionTableName() 보호된 메소드

If no arguments are passed the current configured name is returned. A default name based of the associated tables will be generated if none found.
protected _junctionTableName ( string | null $name = null ) : string
$name string | null The name of the junction table.
리턴 string

_linkField() 보호된 메소드

Generates a string used as a table field that contains the values upon which the filter should be applied
protected _linkField ( array $options ) : string
$options array the options to use for getting the link field.
리턴 string

_options() 보호된 메소드

Parse extra options passed in the constructor.
protected _options ( array $opts ) : void
$opts array original list of options passed in constructor
리턴 void

_saveTarget() 보호된 메소드

Persists each of the entities into the target table and creates links between the parent entity and each one of the saved target entities.
protected _saveTarget ( Cake\Datasource\EntityInterface $parentEntity, array | Traversable $entities, array $options ) : Cake\Datasource\EntityInterface | boolean
$parentEntity Cake\Datasource\EntityInterface the source entity containing the target entities to be saved.
$entities array | Traversable list of entities to persist in target table and to link to the parent entity
$options array list of options accepted by `Table::save()`
리턴 Cake\Datasource\EntityInterface | boolean The parent entity after all links have been created if no errors happened, false otherwise

attachTo() 공개 메소드

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 - 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)
public attachTo ( Query $query, array $options = [] ) : void
$query Cake\ORM\Query the query to be altered to include the target table data
$options array Any extra options or overrides to be taken in account
리턴 void

cascadeDelete() 공개 메소드

Clear out the data in the junction table for a given entity.
public cascadeDelete ( Cake\Datasource\EntityInterface $entity, array $options = [] ) : boolean
$entity Cake\Datasource\EntityInterface The entity that started the cascading delete.
$options array The options for the original delete.
리턴 boolean Success.

conditions() 공개 메소드

{@inheritDoc}
public conditions ( $conditions = null )

find() 공개 메소드

If your association includes conditions, the junction table will be included in the query's contained associations.
또한 보기: Cake\ORM\Table::find()
public find ( string | array | null $type = null, array $options = [] ) : Query
$type string | array | null the type of query to perform, if an array is passed, it will be interpreted as the `$options` parameter
$options array The options to for the find
리턴 Cake\ORM\Query

isOwningSide() 공개 메소드

Returns boolean true, as both of the tables 'own' rows in the other side of the association via the joint table.
public isOwningSide ( Table $side ) : boolean
$side Cake\ORM\Table The potential Table with ownership
리턴 boolean

junction() 공개 메소드

Sets the table instance for the junction relation. If no arguments are passed, the current configured table instance is returned
public junction ( string | Table | null $table = null ) : Table
$table string | Cake\ORM\Table | null Name or instance for the join table
리턴 Cake\ORM\Table

junctionConditions() 보호된 메소드

Returns filtered conditions that specifically reference the junction table.
protected junctionConditions ( ) : array
리턴 array

saveAssociated() 공개 메소드

When using the 'append' strategy, this function will only create new links between each side of this association. It will not destroy existing ones even though they may not be present in the array of entities to be saved. When using the 'replace' strategy, existing links will be removed and new links will be created in the joint table. If there exists links in the database to some of the entities intended to be saved by this method, they will be updated, not deleted.
또한 보기: Cake\ORM\Table::save()
또한 보기: Cake\ORM\Association\BelongsToMany::replaceLinks()
public saveAssociated ( Cake\Datasource\EntityInterface $entity, array $options = [] ) : boolean | Cake\Datasource\EntityInterface
$entity Cake\Datasource\EntityInterface an entity from the source table
$options array options to be passed to the save method in the target table
리턴 boolean | Cake\Datasource\EntityInterface false if $entity could not be saved, otherwise it returns the saved entity

saveStrategy() 공개 메소드

Sets the strategy that should be used for saving. If called with no arguments, it will return the currently configured strategy
public saveStrategy ( string | null $strategy = null ) : string
$strategy string | null the strategy name to be used
리턴 string the strategy to be used for saving

targetConditions() 보호된 메소드

Any string expressions, or expression objects will also be returned in this list.
protected targetConditions ( ) : mixed
리턴 mixed Generally an array. If the conditions are not an array, the association conditions will be returned unmodified.

targetForeignKey() 공개 메소드

If no parameters are passed current field is returned
public targetForeignKey ( string | null $key = null ) : string
$key string | null the key to be used to link both tables together
리턴 string

type() 공개 메소드

Get the relationship type.
public type ( ) : string
리턴 string

프로퍼티 상세

$_dependent 보호되어 있는 프로퍼티

Defaults to true for backwards compatibility.
protected bool $_dependent
리턴 boolean

$_joinType 보호되어 있는 프로퍼티

The type of join to be used when adding the association to a query
protected string $_joinType
리턴 string

$_junctionAssociationName 보호되어 있는 프로퍼티

The name of the hasMany association from the target table to the junction table
protected string $_junctionAssociationName
리턴 string

$_junctionConditions 보호되어 있는 프로퍼티

Filtered conditions that reference the junction table.
protected null|array $_junctionConditions
리턴 null | array

$_junctionProperty 보호되어 있는 프로퍼티

The name of the property to be set containing data from the junction table once a record from the target table is hydrated
protected string $_junctionProperty
리턴 string

$_junctionTable 보호되어 있는 프로퍼티

Junction table instance
protected Table,Cake\ORM $_junctionTable
리턴 Cake\ORM\Table

$_junctionTableName 보호되어 있는 프로퍼티

Junction table name
protected string $_junctionTableName
리턴 string

$_saveStrategy 보호되어 있는 프로퍼티

Saving strategy to be used by this association
protected string $_saveStrategy
리턴 string

$_strategy 보호되어 있는 프로퍼티

The strategy name to be used to fetch associated records.
protected string $_strategy
리턴 string

$_targetConditions 보호되어 있는 프로퍼티

Filtered conditions that reference the target table.
protected null|array $_targetConditions
리턴 null | array

$_targetForeignKey 보호되어 있는 프로퍼티

The name of the field representing the foreign key to the target table
protected string|array $_targetForeignKey
리턴 string | array

$_through 보호되어 있는 프로퍼티

The table instance for the junction relation.
protected string|Table,Cake\ORM $_through
리턴 string | Cake\ORM\Table

$_validStrategies 보호되어 있는 프로퍼티

Valid strategies for this type of association
protected array $_validStrategies
리턴 array