本文整理汇总了PHP中Cake\Database\Query::having方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::having方法的具体用法?PHP Query::having怎么用?PHP Query::having使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Database\Query
的用法示例。
在下文中一共展示了Query::having方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSelectHaving
/**
* Tests that having() behaves pretty much the same as the where() method
*
* @return void
*/
public function testSelectHaving()
{
$query = new Query($this->connection);
$result = $query->select(['total' => 'count(author_id)', 'author_id'])->from('articles')->join(['table' => 'authors', 'alias' => 'a', 'conditions' => 'author_id = a.id'])->group('author_id')->having(['count(author_id) <' => 2], ['count(author_id)' => 'integer'])->execute();
$expected = [['total' => 1, 'author_id' => 3]];
$this->assertEquals($expected, $result->fetchAll('assoc'));
$result = $query->having(['count(author_id)' => 2], ['count(author_id)' => 'integer'], true)->execute();
$expected = [['total' => 2, 'author_id' => 1]];
$this->assertEquals($expected, $result->fetchAll('assoc'));
$result = $query->having(function ($e) {
return $e->add('count(author_id) = 1 + 1');
}, [], true)->execute();
$expected = [['total' => 2, 'author_id' => 1]];
$this->assertEquals($expected, $result->fetchAll('assoc'));
}