Exemplo n.º 1
0
 public function testHavingConditions()
 {
     $c = new ModelCriteria('bookstore', 'Book');
     $c->condition('cond1', 'Book.Title <> ?', 'foo');
     $c->condition('cond2', 'Book.Title like ?', '%bar%');
     $c->having(array('cond1', 'cond2'));
     $sql = "SELECT  FROM  HAVING (book.TITLE <> :p1 AND book.TITLE like :p2)";
     $params = array(array('table' => 'book', 'column' => 'TITLE', 'value' => 'foo'), array('table' => 'book', 'column' => 'TITLE', 'value' => '%bar%'));
     $this->assertCriteriaTranslation($c, $sql, $params, 'having() accepts an array of named conditions');
     $c = new ModelCriteria('bookstore', 'Book');
     $c->condition('cond1', 'Book.Title <> ?', 'foo');
     $c->condition('cond2', 'Book.Title like ?', '%bar%');
     $c->having(array('cond1', 'cond2'), Criteria::LOGICAL_OR);
     $sql = "SELECT  FROM  HAVING (book.TITLE <> :p1 OR book.TITLE like :p2)";
     $this->assertCriteriaTranslation($c, $sql, $params, 'having() accepts an array of named conditions with an operator');
 }
Exemplo n.º 2
0
 public function testSetJoinConditionNamedCondition()
 {
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $c = new ModelCriteria('bookstore', 'Book');
     $c->join('Book.Author', Criteria::INNER_JOIN);
     $c->condition('cond1', 'Book.Title = Author.FirstName');
     $c->setJoinCondition('Author', 'cond1');
     $books = BookPeer::doSelect($c, $con);
     $expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` INNER JOIN `author` ON book.TITLE = author.FIRST_NAME";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'setJoinCondition() can override a previous join condition with a named condition');
 }
 public function testSetJoinConditionNamedCondition()
 {
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $c = new ModelCriteria('bookstore', 'Book');
     $c->join('Book.Author', Criteria::INNER_JOIN);
     $c->condition('cond1', 'Book.Title = Author.FirstName');
     $c->setJoinCondition('Author', 'cond1');
     $books = BookPeer::doSelect($c, $con);
     $expectedSQL = "SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM `book` INNER JOIN `author` ON book.title = author.first_name";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'setJoinCondition() can override a previous join condition with a named condition');
 }