本文整理汇总了PHP中Cake\ORM\Query::hydrate方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::hydrate方法的具体用法?PHP Query::hydrate怎么用?PHP Query::hydrate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Query
的用法示例。
在下文中一共展示了Query::hydrate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findMeetingsThisMonth
public function findMeetingsThisMonth(Query $query, $options = [])
{
$defaultOptions = ['results' => 5];
$options = array_merge($defaultOptions, $options);
// override defaultoptions
$dateFrom = new DateTime('first day of this month');
$query->hydrate(false)->select(['Users.name', 'totalMeetings' => $query->func()->count('Meetings.id')])->matching('Meetings')->where(['Meetings.date >=' => $dateFrom->format('Y-m-d')])->group(['Users.name'])->orderDesc('totalMeetings')->limit($options['results']);
return $query;
}
示例2: beforeFind
public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
{
if (!$query->hydrate()) {
return;
}
$query->formatResults(function ($results) {
return $results->map(function ($row) {
$type = $row[$this->config('typeField')];
$entityClass = $this->_typeMap[$type]['entityClass'];
return new $entityClass($row->forCopy(), ['markNew' => $row->isNew(), 'markClean' => true, 'guard' => false, 'source' => $this->_typeMap[$type]['alias']]);
});
});
}
示例3: __construct
/**
* Constructor
*
* @param \Cake\ORM\Query $query Query from where results come
* @param \Cake\Database\StatementInterface $statement
*/
public function __construct($query, $statement)
{
$repository = $query->repository();
$this->_query = $query;
$this->_statement = $statement;
$this->_defaultTable = $this->_query->repository();
$this->_calculateAssociationMap();
$this->_hydrate = $this->_query->hydrate();
$this->_entityClass = $repository->entityClass();
$this->_useBuffering = $query->bufferResults();
if ($statement) {
$this->count();
}
}
示例4: __construct
/**
* Constructor
*
* @param \Cake\ORM\Query $query Query from where results come
* @param \Cake\Database\StatementInterface $statement The statement to fetch from
*/
public function __construct($query, $statement)
{
$repository = $query->repository();
$this->_query = $query;
$this->_statement = $statement;
$this->_driver = $driver = $this->_query->connection()->driver();
$this->_defaultTable = $this->_query->repository();
$this->_calculateAssociationMap();
$this->_hydrate = $this->_query->hydrate();
$this->_entityClass = $repository->entityClass();
$this->_useBuffering = $query->bufferResults();
$this->_defaultAlias = $this->_defaultTable->alias();
$this->_calculateColumnMap();
$this->_calculateTypeMap();
if ($this->_useBuffering) {
$count = $this->count();
$this->_results = new SplFixedArray($count);
}
}
示例5: _buildResultMap
/**
* Builds an array containing the results from fetchQuery indexed by
* the foreignKey value corresponding to this association.
*
* @param \Cake\ORM\Query $fetchQuery The query to get results from
* @param array $options The options passed to the eager loader
* @return array
* @throws \RuntimeException when the association property is not part of the results set.
*/
protected function _buildResultMap($fetchQuery, $options)
{
$resultMap = [];
$key = (array) $options['foreignKey'];
$property = $this->target()->association($this->junction()->alias())->property();
$hydrated = $fetchQuery->hydrate();
foreach ($fetchQuery->all() as $result) {
if (!isset($result[$property])) {
throw new RuntimeException(sprintf('"%s" is missing from the belongsToMany results. Results cannot be created.', $property));
}
$result[$this->_junctionProperty] = $result[$property];
unset($result[$property]);
if ($hydrated) {
$result->dirty($this->_junctionProperty, false);
}
$values = [];
foreach ($key as $k) {
$values[] = $result[$this->_junctionProperty][$k];
}
$resultMap[implode(';', $values)][] = $result;
}
return $resultMap;
}
示例6: testFirstUnbuffered
/**
* Tests that first can be called on an unbuffered query
*
* @return void
*/
public function testFirstUnbuffered()
{
$table = TableRegistry::get('Articles');
$query = new Query($this->connection, $table);
$query->select(['id']);
$first = $query->hydrate(false)->bufferResults(false)->first();
$this->assertEquals(['id' => 1], $first);
}
示例7: _buildResultMap
/**
* Builds an array containing the results from fetchQuery indexed by
* the foreignKey value corresponding to this association.
*
* @param \Cake\ORM\Query $fetchQuery The query to get results from
* @param array $options The options passed to the eager loader
* @return array
*/
protected function _buildResultMap($fetchQuery, $options)
{
$resultMap = [];
$key = (array) $options['foreignKey'];
$property = $this->target()->association($this->junction()->alias())->property();
$hydrated = $fetchQuery->hydrate();
foreach ($fetchQuery->all() as $result) {
$result[$this->_junctionProperty] = $result[$property];
unset($result[$property]);
if ($hydrated) {
$result->dirty($this->_junctionProperty, false);
}
$values = [];
foreach ($key as $k) {
$values[] = $result[$this->_junctionProperty][$k];
}
$resultMap[implode(';', $values)][] = $result;
}
return $resultMap;
}
示例8: testFirstSameResult
/**
* Tests that first() will not execute the same query twice
*
* @return void
*/
public function testFirstSameResult()
{
$table = TableRegistry::get('articles', ['table' => 'articles']);
$query = new Query($this->connection, $table);
$query->select(['id'])->toArray();
$first = $query->hydrate(false)->first();
$resultSet = $query->all();
$this->assertEquals(['id' => 1], $first);
$this->assertSame($resultSet, $query->all());
}