/** * @expectedException PropelException */ public function testFindOneWithOneToManyAndLimit() { $c = new ModelCriteria('bookstore', 'Book'); $c->setFormatter(ModelCriteria::FORMAT_ARRAY); $c->add(BookPeer::ISBN, '043935806X'); $c->leftJoin('Book.Review'); $c->with('Review'); $c->limit(5); $books = $c->find(); }
public function testOffset() { $c = new ModelCriteria('bookstore', 'Book'); $c->limit(50); $c->offset(10); $sql = 'SELECT FROM LIMIT 10, 50'; $params = array(); $this->assertCriteriaTranslation($c, $sql, $params, 'offset() adds an OFFSET clause'); }
public function testFindOneWithClassAndColumn() { BookstoreDataPopulator::populate(); BookPeer::clearInstancePool(); AuthorPeer::clearInstancePool(); ReviewPeer::clearInstancePool(); $c = new ModelCriteria('bookstore', 'Book'); $c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND); $c->filterByTitle('The Tin Drum'); $c->join('Book.Author'); $c->withColumn('Author.FirstName', 'AuthorName'); $c->withColumn('Author.LastName', 'AuthorName2'); $c->with('Author'); $c->limit(1); $con = Propel::getConnection(BookPeer::DATABASE_NAME); $books = $c->find($con); foreach ($books as $book) { break; } $this->assertTrue($book instanceof Book, 'withColumn() do not change the resulting model class'); $this->assertEquals('The Tin Drum', $book->getTitle()); $this->assertTrue($book->getAuthor() instanceof Author, 'PropelObjectFormatter correctly hydrates with class'); $this->assertEquals('Gunter', $book->getAuthor()->getFirstName(), 'PropelObjectFormatter correctly hydrates with class'); $this->assertEquals('Gunter', $book->getVirtualColumn('AuthorName'), 'PropelObjectFormatter adds withColumns as virtual columns'); $this->assertEquals('Grass', $book->getVirtualColumn('AuthorName2'), 'PropelObjectFormatter correctly hydrates all virtual columns'); }
public function testAddJoinConditionWithNotInOperator() { $con = Propel::getConnection(BookPeer::DATABASE_NAME); $c = new ModelCriteria('bookstore', 'Author'); $c->join('Author.Book', Criteria::LEFT_JOIN); $c->addJoinCondition('Book', 'Book.isbn NOT IN ?', array(1, 7, 42)); $c->limit(1); $books = AuthorPeer::doSelect($c, $con); $expectedSQL = "SELECT author.id, author.first_name, author.last_name, author.email, author.age FROM `author` LEFT JOIN `book` ON (author.id=book.author_id AND book.isbn NOT IN (1,7,42)) LIMIT 1"; $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'addJoinCondition() allows the use of custom conditions'); }