當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Association::attachTo方法代碼示例

本文整理匯總了PHP中Cake\ORM\Association::attachTo方法的典型用法代碼示例。如果您正苦於以下問題:PHP Association::attachTo方法的具體用法?PHP Association::attachTo怎麽用?PHP Association::attachTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\ORM\Association的用法示例。


在下文中一共展示了Association::attachTo方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: attachTo

 /**
  * 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
  * - 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)
  *
  * @param Query $query the query to be altered to include the target table data
  * @param array $options Any extra options or overrides to be taken in account
  * @return void
  */
 public function attachTo(Query $query, array $options = [])
 {
     parent::attachTo($query, $options);
     $junction = $this->junction();
     $belongsTo = $junction->association($this->source()->alias());
     $cond = $belongsTo->_joinCondition(['foreignKey' => $belongsTo->foreignKey()]);
     if (isset($options['includeFields'])) {
         $includeFields = $options['includeFields'];
     }
     unset($options['queryBuilder']);
     $options = ['conditions' => [$cond]] + compact('includeFields');
     $options['foreignKey'] = $this->targetForeignKey();
     $assoc = $this->_targetTable->association($junction->alias());
     $assoc->attachTo($query, $options);
     $query->eagerLoader()->addToJoinsMap($junction->alias(), $assoc, true);
 }
開發者ID:nuwe1,項目名稱:cakephp,代碼行數:33,代碼來源:BelongsToMany.php

示例2: attachTo

 /**
  * 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
  * - 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)
  *
  * @param Query $query the query to be altered to include the target table data
  * @param array $options Any extra options or overrides to be taken in account
  * @return void
  */
 public function attachTo(Query $query, array $options = [])
 {
     parent::attachTo($query, $options);
     $junction = $this->junction();
     $belongsTo = $junction->association($this->source()->alias());
     $cond = $belongsTo->_joinCondition(['foreignKey' => $belongsTo->foreignKey()]);
     $cond += $this->junctionConditions();
     if (isset($options['includeFields'])) {
         $includeFields = $options['includeFields'];
     }
     // Attach the junction table as well we need it to populate _joinData.
     $assoc = $this->_targetTable->association($junction->alias());
     $query->removeJoin($assoc->name());
     $options = array_intersect_key($options, ['joinType' => 1, 'fields' => 1]);
     $options += ['conditions' => $cond, 'includeFields' => $includeFields, 'foreignKey' => $this->targetForeignKey()];
     $assoc->attachTo($query, $options);
     $query->eagerLoader()->addToJoinsMap($junction->alias(), $assoc, true);
 }
開發者ID:Mingyangzu,項目名稱:PHP-cakephp,代碼行數:35,代碼來源:BelongsToMany.php

示例3: attachTo

 /**
  * 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
  * - 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)
  *
  * @param \Cake\ORM\Query $query the query to be altered to include the target table data
  * @param array $options Any extra options or overrides to be taken in account
  * @return void
  */
 public function attachTo(Query $query, array $options = [])
 {
     if (!empty($options['negateMatch'])) {
         $this->_appendNotMatching($query, $options);
         return;
     }
     $junction = $this->junction();
     $belongsTo = $junction->association($this->source()->alias());
     $cond = $belongsTo->_joinCondition(['foreignKey' => $belongsTo->foreignKey()]);
     $cond += $this->junctionConditions();
     if (isset($options['includeFields'])) {
         $includeFields = $options['includeFields'];
     }
     // Attach the junction table as well we need it to populate _joinData.
     $assoc = $this->_targetTable->association($junction->alias());
     $newOptions = array_intersect_key($options, ['joinType' => 1, 'fields' => 1]);
     $newOptions += ['conditions' => $cond, 'includeFields' => $includeFields, 'foreignKey' => false];
     $assoc->attachTo($query, $newOptions);
     $query->eagerLoader()->addToJoinsMap($junction->alias(), $assoc, true);
     parent::attachTo($query, $options);
     $foreignKey = $this->targetForeignKey();
     $thisJoin = $query->clause('join')[$this->name()];
     $thisJoin['conditions']->add($assoc->_joinCondition(['foreignKey' => $foreignKey]));
 }
開發者ID:ramb0Ram,項目名稱:cakephp,代碼行數:41,代碼來源:BelongsToMany.php


注:本文中的Cake\ORM\Association::attachTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。