Example #1
0
    function testGetTablesClauseMultipleTablesWithJoin()
    {
        $q = new Query('Article');
        $q->join('UserCard', 'Article.CardID = UserCard.CardID AND UserCard.UserID = 2', Query::LEFT_JOIN);
        $q->add('UserCard.CardID', null, Query::IS_NULL);
        $q->join('CardPicture');
        $q->group('Article.CardID');
        $q->addOrder('Title', 'DESC');
        $this->assertEquals(preg_replace('/\\s/', '', 'SELECT `Article`.*
FROM (`Article`, `CardPicture`)
LEFT JOIN `UserCard` ON (Article.CardID = UserCard.CardID AND UserCard.UserID = 2)
WHERE `UserCard`.`CardID` IS NULL
GROUP BY `Article`.`CardID`
ORDER BY `Title` DESC'), preg_replace('/\\s/', '', $q->getQuery() . ''));
    }
 /**
  * Returns the passed query after rewriting the DISTINCT clause, so that drivers
  * that do not support the "ON" part can provide the actual way it should be done
  *
  * @param Query $query The query to be transformed
  * @return Query
  */
 protected function _transformDistinct($query)
 {
     if (is_array($query->clause('distinct'))) {
         $query->group($query->clause('distinct'), true);
         $query->distinct(false);
     }
     return $query;
 }