public function testaddUsingOperatorResetsDefaultOperator() { $c = new Criteria(); $c->addUsingOperator('foo1', 'bar1'); $c->_or(); $c->addUsingOperator('foo2', 'bar2'); $c->addUsingOperator('foo3', 'bar3'); $expected = 'SELECT FROM WHERE (foo1=:p1 OR foo2=:p2) AND foo3=:p3'; $params = array(); $result = $c->createSelectSql($params); $this->assertEquals($expected, $result); }
public function testMerge_OrWithWhereConditions() { $c1 = new Criteria(); $c1->add(BookTableMap::COL_TITLE, 'foo'); $c2 = new Criteria(); $c1->_or(); $c1->mergeWith($c2); $sql = $this->getSql('SELECT FROM `book` WHERE book.TITLE=:p1'); $this->assertCriteriaTranslation($c1, $sql, 'mergeWith() does not remove an existing where condition'); $c1 = new Criteria(); $c2 = new Criteria(); $c2->add(BookTableMap::COL_TITLE, 'foo'); $c1->_or(); $c1->mergeWith($c2); $sql = $this->getSql('SELECT FROM `book` WHERE book.TITLE=:p1'); $this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges where condition to an empty condition'); $c1 = new Criteria(); $c1->add(BookTableMap::COL_ID, 123); $c1->_or(); $c2 = new Criteria(); $c2->add(BookTableMap::COL_TITLE, 'foo'); $c1->mergeWith($c2); $sql = $this->getSql('SELECT FROM `book` WHERE (book.ID=:p1 OR book.TITLE=:p2)'); $this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges where condition to existing conditions'); $c1 = new Criteria(); $c1->add(BookTableMap::COL_TITLE, 'foo'); $c1->_or(); $c2 = new Criteria(); $c2->add(BookTableMap::COL_TITLE, 'bar'); $c1->mergeWith($c2); $sql = $this->getSql('SELECT FROM `book` WHERE (book.TITLE=:p1 OR book.TITLE=:p2)'); $this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges where condition to existing conditions on the same column'); $c1 = new Criteria(); $c1->add(BookTableMap::COL_TITLE, 'foo'); $c1->addJoin(BookTableMap::COL_AUTHOR_ID, AuthorTableMap::COL_ID, Criteria::LEFT_JOIN); $c1->_or(); $c2 = new Criteria(); $c2->add(AuthorTableMap::COL_FIRST_NAME, 'bar'); $c1->mergeWith($c2); $sql = $this->getSql('SELECT FROM `book` LEFT JOIN `author` ON (book.AUTHOR_ID=author.ID) WHERE (book.TITLE=:p1 OR author.FIRST_NAME=:p2)'); $this->assertCriteriaTranslation($c1, $sql, 'mergeWith() merges where condition to existing conditions on the different tables'); }
/** * @param \Generated\Shared\Transfer\LocaleTransfer $localeTransfer * * @return \Propel\Runtime\ActiveQuery\Criteria */ protected function getLocaleCriteria(LocaleTransfer $localeTransfer) { $localeCriteria = new Criteria(); $localeCriteria->addAnd(PavCmsLocalizedBlockTableMap::COL_FK_LOCALE, $localeTransfer->getIdLocale(), Criteria::EQUAL); $localeCriteria->_or(); $localeCriteria->addAnd(PavCmsLocalizedBlockTableMap::COL_ID_CMS_LOCALIZED_BLOCK, null, Criteria::ISNULL); return $localeCriteria; }