当前位置: 首页>>代码示例>>PHP>>正文


PHP Query::aliasField方法代码示例

本文整理汇总了PHP中Cake\ORM\Query::aliasField方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::aliasField方法的具体用法?PHP Query::aliasField怎么用?PHP Query::aliasField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\ORM\Query的用法示例。


在下文中一共展示了Query::aliasField方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _resultInjector

 /**
  * Returns a callable to be used for each row in a query result set
  * for injecting the eager loaded rows
  *
  * @param \Cake\ORM\Query $fetchQuery the Query used to fetch results
  * @param array $resultMap an array with the foreignKey as keys and
  * the corresponding target table results as value.
  * @param array $options The options passed to the eagerLoader method
  * @return \Closure
  */
 protected function _resultInjector($fetchQuery, $resultMap, $options)
 {
     $source = $this->source();
     $sAlias = $source->alias();
     $keys = $this->type() === $this::MANY_TO_ONE ? $this->foreignKey() : $this->bindingKey();
     $sourceKeys = [];
     foreach ((array) $keys as $key) {
         $sourceKeys[] = key($fetchQuery->aliasField($key, $sAlias));
     }
     $nestKey = $options['nestKey'];
     if (count($sourceKeys) > 1) {
         return $this->_multiKeysInjector($resultMap, $sourceKeys, $nestKey);
     }
     $sourceKey = $sourceKeys[0];
     return function ($row) use($resultMap, $sourceKey, $nestKey) {
         if (isset($resultMap[$row[$sourceKey]])) {
             $row[$nestKey] = $resultMap[$row[$sourceKey]];
         }
         return $row;
     };
 }
开发者ID:wepbunny,项目名称:cake2,代码行数:31,代码来源:SelectableAssociationTrait.php

示例2: _collectKeys

 /**
  * Helper function used to return the keys from the query records that will be used
  * to eagerly load associations.
  *
  * @param array $external the list of external associations to be loaded
  * @param \Cake\ORM\Query $query The query from which the results where generated
  * @param BufferedStatement $statement The statement to work on
  * @return array
  */
 protected function _collectKeys($external, $query, $statement)
 {
     $collectKeys = [];
     foreach ($external as $meta) {
         $instance = $meta->instance();
         if (!$instance->requiresKeys($meta->config())) {
             continue;
         }
         $source = $instance->source();
         $keys = $instance->type() === Association::MANY_TO_ONE ? (array) $instance->foreignKey() : (array) $instance->bindingKey();
         $alias = $source->alias();
         $pkFields = [];
         foreach ($keys as $key) {
             $pkFields[] = key($query->aliasField($key, $alias));
         }
         $collectKeys[$meta->aliasPath()] = [$alias, $pkFields, count($pkFields) === 1];
     }
     if (empty($collectKeys)) {
         return [[], $statement];
     }
     if (!$statement instanceof BufferedStatement) {
         $statement = new BufferedStatement($statement, $query->connection()->driver());
     }
     return [$this->_groupKeys($statement, $collectKeys), $statement];
 }
开发者ID:sergiochollet,项目名称:kiwi-cake,代码行数:34,代码来源:EagerLoader.php

示例3: _addFieldsToQuery

 /**
  * Add translation fields to query
  *
  * If the query is using autofields (directly or implicitly) add the
  * main table's fields to the query first.
  *
  * Only add translations for fields that are in the main table, always
  * add the locale field though.
  *
  * @param \Cake\ORM\Query $query the query to check
  * @param array $config the config to use for adding fields
  * @return bool Whether a join to the translation table is required
  */
 protected function _addFieldsToQuery(Query $query, array $config)
 {
     $select = $query->clause('select');
     if (!$select) {
         return true;
     }
     $alias = $config['mainTableAlias'];
     $joinRequired = false;
     foreach ($this->_translationFields() as $field) {
         if (array_intersect($select, [$field, "{$alias}.{$field}"])) {
             $joinRequired = true;
             $query->select($query->aliasField($field, $config['hasOneAlias']));
         }
     }
     if ($joinRequired) {
         $query->select($query->aliasField('locale', $config['hasOneAlias']));
     }
     return $joinRequired;
 }
开发者ID:adayth,项目名称:cakephp-shadow-translate,代码行数:32,代码来源:ShadowTranslateBehavior.php


注:本文中的Cake\ORM\Query::aliasField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。