本文整理汇总了PHP中Cake\ORM\Query::eagerLoader方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::eagerLoader方法的具体用法?PHP Query::eagerLoader怎么用?PHP Query::eagerLoader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Query
的用法示例。
在下文中一共展示了Query::eagerLoader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProperty
/**
* Get CakePHP property
*
* @param string $dataName Column data name
*
* @throws Exception
* @return array|string
*/
protected function getProperty($dataName)
{
$dataName = explode('.', trim($dataName));
if (count($dataName) != 2) {
throw new Exception('You are set invalid date.');
}
$tableAlias = $dataName[0];
$colName = $dataName[1];
if ($this->query->repository()->alias() == $tableAlias) {
return $colName;
} elseif (array_key_exists($tableAlias, $this->query->contain())) {
return ['propertyPath' => $this->query->eagerLoader()->normalized($this->query->repository())[$tableAlias]['propertyPath'], 'field' => $colName];
}
}
示例2: _calculateAssociationMap
/**
* Calculates the list of associations that should get eager loaded
* when fetching each record
*
* @return void
*/
protected function _calculateAssociationMap()
{
$contain = $this->_query->eagerLoader()->normalized($this->_defaultTable);
if (!$contain) {
return;
}
$map = [];
$visitor = function ($level) use(&$visitor, &$map) {
foreach ($level as $assoc => $meta) {
$map[$meta['aliasPath']] = ['alias' => $assoc, 'instance' => $meta['instance'], 'canBeJoined' => $meta['canBeJoined'], 'entityClass' => $meta['instance']->target()->entityClass(), 'nestKey' => $meta['canBeJoined'] ? $assoc : $meta['aliasPath']];
if ($meta['canBeJoined'] && !empty($meta['associations'])) {
$visitor($meta['associations']);
}
}
};
$visitor($contain, []);
$this->_associationMap = $map;
}
示例3: _appendJunctionJoin
/**
* Append a join to the junction table.
*
* @param \Cake\ORM\Query $query The query to append.
* @param string|array $conditions The query conditions to use.
* @return \Cake\ORM\Query The modified query.
*/
protected function _appendJunctionJoin($query, $conditions)
{
$name = $this->_junctionAssociationName();
$joins = $query->join();
$matching = [$name => ['table' => $this->junction()->table(), 'conditions' => $conditions, 'type' => 'INNER']];
$assoc = $this->target()->association($name);
$query->addDefaultTypes($assoc->target())->join($matching + $joins, [], true);
$query->eagerLoader()->addToJoinsMap($name, $assoc);
return $query;
}
示例4: _bindNewAssociations
/**
* Applies all attachable associations to `$query` out of the containments found
* in the `$surrogate` query.
*
* Copies all contained associations from the `$surrogate` query into the
* passed `$query`. Containments are altered so that they respect the associations
* chain from which they originated.
*
* @param \Cake\ORM\Query $query the query that will get the associations attached to
* @param \Cake\ORM\Query $surrogate the query having the containments to be attached
* @param array $options options passed to the method `attachTo`
* @return void
*/
protected function _bindNewAssociations($query, $surrogate, $options)
{
$loader = $surrogate->eagerLoader();
$contain = $loader->contain();
$matching = $loader->matching();
if (!$contain && !$matching) {
return;
}
$newContain = [];
foreach ($contain as $alias => $value) {
$newContain[$options['aliasPath'] . '.' . $alias] = $value;
}
$eagerLoader = $query->eagerLoader();
$eagerLoader->contain($newContain);
foreach ($matching as $alias => $value) {
$eagerLoader->matching($options['aliasPath'] . '.' . $alias, $value['queryBuilder'], $value);
}
}
示例5: _calculateAssociationMap
/**
* Calculates the list of associations that should get eager loaded
* when fetching each record
*
* @return void
*/
protected function _calculateAssociationMap()
{
$map = $this->_query->eagerLoader()->associationsMap($this->_defaultTable);
$this->_matchingMap = (new Collection($map))->match(['matching' => true])->indexBy('alias')->toArray();
$this->_containMap = (new Collection(array_reverse($map)))->match(['matching' => false])->indexBy('nestKey')->toArray();
}
示例6: _bindNewAssociations
/**
* Applies all attachable associations to `$query` out of the containments found
* in the `$surrogate` query.
*
* Copies all contained associations from the `$surrogate` query into the
* passed `$query`. Containments are altered so that they respect the associations
* chain from which they originated.
*
* @param \Cake\ORM\Query $query the query that will get the associations attached to
* @param \Cake\ORM\Query $surrogate the query having the containments to be attached
* @param array $options options passed to the method `attachTo`
* @return void
*/
protected function _bindNewAssociations($query, $surrogate, $options)
{
$loader = $surrogate->eagerLoader();
$contain = $loader->contain();
$matching = $loader->matching();
$target = $this->_targetTable;
if (!$contain && !$matching) {
return;
}
$loader->attachAssociations($query, $target, $options['includeFields']);
$newContain = [];
foreach ($contain as $alias => $value) {
$newContain[$options['aliasPath'] . '.' . $alias] = $value;
}
$query->contain($newContain);
foreach ($matching as $alias => $value) {
$query->matching($options['aliasPath'] . '.' . $alias, $value['queryBuilder']);
}
}
示例7: _bindNewAssociations
/**
* Applies all attachable associations to `$query` out of the containments found
* in the `$surrogate` query.
*
* Copies all contained associations from the `$surrogate` query into the
* passed `$query`. Containments are altered so that they respect the associations
* chain from which they originated.
*
* @param \Cake\ORM\Query $query the query that will get the associations attached to
* @param \Cake\ORM\Query $surrogate the query having the containments to be attached
* @param array $options options passed to the method `attachTo`
* @return void
*/
protected function _bindNewAssociations($query, $surrogate, $options)
{
$contain = $surrogate->contain();
$target = $this->_targetTable;
if (!$contain) {
return;
}
$loader = $surrogate->eagerLoader();
$loader->attachAssociations($query, $target, $options['includeFields']);
$newBinds = [];
foreach ($contain as $alias => $value) {
$newBinds[$options['aliasPath'] . '.' . $alias] = $value;
}
$query->contain($newBinds);
}