本文整理汇总了PHP中Cake\Database\Query::join方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::join方法的具体用法?PHP Query::join怎么用?PHP Query::join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Database\Query
的用法示例。
在下文中一共展示了Query::join方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSubqueyInJoin
/**
* Tests that it is possible to use a subquery in a join clause
*
* @return void
*/
public function testSubqueyInJoin()
{
$subquery = (new Query($this->connection))->select('*')->from('authors');
$query = new Query($this->connection);
$result = $query->select(['title', 'name'])->from('articles')->join(['b' => $subquery])->execute();
$this->assertCount(self::ARTICLE_COUNT * self::AUTHOR_COUNT, $result, 'Cross join causes multiplication');
$subquery->where(['id' => 1]);
$result = $query->execute();
$this->assertCount(3, $result);
$query->join(['b' => ['table' => $subquery, 'conditions' => ['b.id = articles.id']]], [], true);
$result = $query->execute();
$this->assertCount(1, $result);
}
示例2: _quoteParts
/**
* Quotes all identifiers in each of the clauses of a query
*
* @param \Cake\Database\Query $query The query to quote.
* @return void
*/
protected function _quoteParts($query)
{
foreach (['distinct', 'select', 'from', 'group'] as $part) {
$contents = $query->clause($part);
if (!is_array($contents)) {
continue;
}
$result = $this->_basicQuoter($contents);
if (!empty($result)) {
$query->{$part}($result, true);
}
}
$joins = $query->clause('join');
if ($joins) {
$joins = $this->_quoteJoins($joins);
$query->join($joins, [], true);
}
}
示例3: beforeFind
public function beforeFind(Event $event, Query $query, ArrayObject $options)
{
$query->join(['table' => 'pessoas_associacoes', 'alias' => 'PessoasAssociacoes', 'type' => 'INNER', 'conditions' => ['PessoasAssociacoes.pessoa_id = ' . $this->aliasField('pessoa_id'), 'PessoasAssociacoes.tipo_associacao' => 7, 'PessoasAssociacoes.status !=' => 9]]);
$query->group($this->aliasField('pessoa_id'));
}
示例4: testRemoveJoin
/**
* Test removeJoin().
*
* @return void
*/
public function testRemoveJoin()
{
$query = new Query($this->connection);
$query->select(['id', 'title'])->from('articles')->join(['authors' => ['type' => 'INNER', 'conditions' => ['articles.author_id = authors.id']]]);
$this->assertArrayHasKey('authors', $query->join());
$this->assertSame($query, $query->removeJoin('authors'));
$this->assertArrayNotHasKey('authors', $query->join());
}