本文整理汇总了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;
};
}
示例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];
}
示例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;
}