本文整理汇总了PHP中Cake\ORM\Query::select方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::select方法的具体用法?PHP Query::select怎么用?PHP Query::select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Query
的用法示例。
在下文中一共展示了Query::select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findWithCount
public function findWithCount(Query $query, array $options)
{
$query->select(['count' => $query->func()->count('Users.id')]);
$query->matching('Users');
$query->group(['UserRoles.id']);
return $query;
}
示例2: findDistance
/**
* Custom finder for distance.
*
* Options:
* - lat (required)
* - lng (required)
* - tableName
* - distance
*
* @param \Cake\ORM\Query $query Query.
* @param array $options Array of options as described above
* @return \Cake\ORM\Query
*/
public function findDistance(Query $query, array $options)
{
$options += ['tableName' => null];
$sql = $this->distance($options['lat'], $options['lng'], null, null, $options['tableName']);
$query->select(['distance' => $query->newExpr($sql)]);
if (isset($options['distance'])) {
// Some SQL versions cannot reuse the select() distance field, so we better reuse the $sql snippet
$query->where(['(' . $sql . ') <' => $options['distance']]);
}
return $query->order(['distance' => 'ASC']);
}
示例3: findAuth
/**
* Custom finder
*
* @param \Cake\ORM\Query $query The query to find with
* @param array $options The options to find with
* @return \Cake\ORM\Query The query builder
*/
public function findAuth(Query $query, array $options)
{
$query->select(['id', 'username', 'password']);
if (!empty($options['return_created'])) {
$query->select(['created']);
}
return $query;
}
示例4: _addFilteringJoin
/**
* Appends any conditions required to load the relevant set of records in the
* target table query given a filter key and some filtering values when the
* filtering needs to be done using a subquery.
*
* @param \Cake\ORM\Query $query Target table's query
* @param string $key the fields that should be used for filtering
* @param \Cake\ORM\Query $subquery The Subquery to use for filtering
* @return \Cake\ORM\Query
*/
public function _addFilteringJoin($query, $key, $subquery)
{
$filter = [];
$aliasedTable = $this->source()->alias();
foreach ($subquery->clause('select') as $aliasedField => $field) {
$filter[] = new IdentifierExpression($field);
}
$subquery->select($filter, true);
if (is_array($key)) {
$conditions = $this->_createTupleCondition($query, $key, $filter, '=');
} else {
$filter = current($filter);
}
$conditions = isset($conditions) ? $conditions : $query->newExpr([$key => $filter]);
return $query->innerJoin([$aliasedTable => $subquery], $conditions);
}
示例5: findFull
/**
* Custom finder for select full fields.
*
* @param \Cake\ORM\Query $query The query finder.
*
* @return \Cake\ORM\Query
*/
public function findFull(Query $query)
{
return $query->select(['id', 'first_name', 'last_name', 'username', 'avatar', 'slug', 'group_id', 'forum_post_count', 'forum_thread_count', 'forum_like_received', 'blog_articles_comment_count', 'blog_article_count', 'facebook', 'twitter', 'signature', 'end_subscription', 'created', 'last_login']);
}
示例6: _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;
}
示例7: testContainToFieldsDefault
/**
* Tests that default fields for associations are added to the select clause when
* none is specified
*
* @return void
*/
public function testContainToFieldsDefault()
{
$contains = ['clients' => ['orders']];
$query = new Query($this->connection, $this->table);
$query->select()->contain($contains)->sql();
$select = $query->clause('select');
$expected = ['foo__id' => 'foo.id', 'clients__name' => 'clients.name', 'clients__id' => 'clients.id', 'clients__phone' => 'clients.phone', 'orders__id' => 'orders.id', 'orders__total' => 'orders.total', 'orders__placed' => 'orders.placed'];
$expected = $this->_quoteArray($expected);
$this->assertEquals($expected, $select);
$contains['clients']['fields'] = ['name'];
$query = new Query($this->connection, $this->table);
$query->select('foo.id')->contain($contains)->sql();
$select = $query->clause('select');
$expected = ['foo__id' => 'foo.id', 'clients__name' => 'clients.name'];
$expected = $this->_quoteArray($expected);
$this->assertEquals($expected, $select);
$contains['clients']['fields'] = [];
$contains['clients']['orders']['fields'] = false;
$query = new Query($this->connection, $this->table);
$query->select()->contain($contains)->sql();
$select = $query->clause('select');
$expected = ['foo__id' => 'foo.id', 'clients__id' => 'clients.id', 'clients__name' => 'clients.name', 'clients__phone' => 'clients.phone'];
$expected = $this->_quoteArray($expected);
$this->assertEquals($expected, $select);
}
示例8: findDistance
/**
* Custom finder for distance.
*
* Options:
* - lat (required)
* - lng (required)
* - tableName
* - distance
* - sort
*
* @param \Cake\ORM\Query $query Query.
* @param array $options Array of options as described above
* @return \Cake\ORM\Query
*/
public function findDistance(Query $query, array $options)
{
$options += ['tableName' => null, 'sort' => true];
$sql = $this->distanceExpr($options['lat'], $options['lng'], null, null, $options['tableName']);
if ($query->autoFields() === null) {
$query->autoFields(true);
}
$query->select(['distance' => $query->newExpr($sql)]);
if (isset($options['distance'])) {
// Some SQL versions cannot reuse the select() distance field, so we better reuse the $sql snippet
$query->where(function ($exp) use($sql, $options) {
return $exp->lt($sql, $options['distance']);
});
}
if ($options['sort']) {
$sort = $options['sort'] === true ? 'ASC' : $options['sort'];
$query->order(['distance' => $sort]);
}
return $query;
}
示例9: findAuth
public function findAuth(Query $query, array $option)
{
$query->select(['id', 'email', 'password'])->where(['Users.active' => 1]);
return $query;
}
示例10: _appendFields
/**
* Helper function used to conditionally append fields to the select clause of
* a query from the fields found in another query object.
*
* @param \Cake\ORM\Query $query the query that will get the fields appended to
* @param \Cake\ORM\Query $surrogate the query having the fields to be copied from
* @param array $options options passed to the method `attachTo`
* @return void
*/
protected function _appendFields($query, $surrogate, $options)
{
$options['fields'] = $surrogate->clause('select') ?: $options['fields'];
$target = $this->_targetTable;
if (empty($options['fields'])) {
$f = isset($options['fields']) ? $options['fields'] : null;
if ($options['includeFields'] && ($f === null || $f !== false)) {
$options['fields'] = $target->schema()->columns();
}
}
if (!empty($options['fields'])) {
$query->select($query->aliasFields($options['fields'], $target->alias()));
}
}
示例11: _selectActionFields
/**
* Method that adds SELECT clause to the Query to only include
* action fields (as defined in the csv file).
*
* @param \Cake\ORM\Query $query Query object
* @param \Cake\Event\Event $event The event
* @return void
*/
protected function _selectActionFields(Query $query, Event $event)
{
if (!in_array($event->subject()->request->query('format'), [static::FORMAT_DATATABLES])) {
return;
}
$fields = $this->_getActionFields($event->subject()->request);
if (empty($fields)) {
return;
}
$primaryKey = $event->subject()->{$event->subject()->name}->primaryKey();
// always include primary key, useful for menus URLs
if (!in_array($primaryKey, $fields)) {
array_push($fields, $primaryKey);
}
$query->select($this->_databaseFields($fields, $event), true);
}
示例12: findAverageLifeExpectancy
public function findAverageLifeExpectancy(Query $query)
{
return $query->select(['average_exp' => $query->func()->avg('life_expectancy')]);
}
示例13: findAdmin
/**
* Find usado primeiramente pela autenticação
*/
public function findAdmin(Query $query, array $options)
{
$query->select(['id', 'email', 'password'])->where(['active' => 1, 'role' => 1]);
return $query;
}
示例14: findOfficialLanguages
public function findOfficialLanguages(Query $query)
{
return $query->select(['language'])->where(['is_official' => true])->distinct(['language'])->hydrate(false);
}
示例15: findDistance
/**
* Custom finder for distance.
*
* Used to be a virtual field in 2.x via setDistanceAsVirtualField()
*
* Options:
* - lat (required)
* - lng (required)
* - tableName
* - distance
*
* @param \Cake\ORM\Query $query Query.
* @param array $options Array of options as described above
* @return \Cake\ORM\Query
*/
public function findDistance(Query $query, array $options)
{
$options += array('tableName' => null);
$sql = $this->distance($options['lat'], $options['lng'], null, null, $options['tableName']);
$query->select(['distance' => $query->newExpr($sql)]);
if (isset($options['distance'])) {
$query->where(['distance <' => $options['distance']]);
}
return $query->order(['distance' => 'ASC']);
}