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


PHP Query::hydrate方法代码示例

本文整理汇总了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;
 }
开发者ID:bolshas,项目名称:voffice,代码行数:9,代码来源:UsersTable.php

示例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']]);
         });
     });
 }
开发者ID:UseMuffin,项目名称:Sti,代码行数:13,代码来源:StiBehavior.php

示例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();
     }
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:20,代码来源:ResultSet.php

示例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);
     }
 }
开发者ID:QueenCityCodeFactory,项目名称:cakephp,代码行数:25,代码来源:ResultSet.php

示例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;
 }
开发者ID:Mingyangzu,项目名称:PHP-cakephp,代码行数:32,代码来源:BelongsToMany.php

示例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);
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:13,代码来源:QueryTest.php

示例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;
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:28,代码来源:BelongsToMany.php

示例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());
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:15,代码来源:QueryTest.php


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