本文整理匯總了PHP中Propel\Tests\Bookstore\BookQuery::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP BookQuery::create方法的具體用法?PHP BookQuery::create怎麽用?PHP BookQuery::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Propel\Tests\Bookstore\BookQuery
的用法示例。
在下文中一共展示了BookQuery::create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testSerializeHydratedObject
public function testSerializeHydratedObject()
{
$book = new Book();
$book->setTitle('Foo3');
$book->setISBN('1234');
$book->save();
BookTableMap::clearInstancePool();
$book = BookQuery::create()->findOneByTitle('Foo3');
$sb = serialize($book);
$this->assertEquals($book, unserialize($sb));
}
示例2: testFilterById
/**
* testFilterById
*
* Various test for filterById functions
* Id's are autoincrement so we have to use a Select to get current ID's
*
*/
public function testFilterById()
{
// find by single id
$book = PropelQuery::from('\\Propel\\Tests\\Bookstore\\Book b')->where('b.Title like ?', 'Don%')->orderBy('b.ISBN', 'desc')->findOne();
$c = BookQuery::create()->filterById($book->getId());
$book2 = $c->findOne();
$this->assertTrue($book2 instanceof Book);
$this->assertEquals('Don Juan', $book2->getTitle());
//find range
$booksAll = PropelQuery::from('\\Propel\\Tests\\Bookstore\\Book b')->orderBy('b.ID', 'asc')->find();
$booksIn = BookQuery::create()->filterById([$booksAll[1]->getId(), $booksAll[2]->getId()])->find();
$this->assertTrue($booksIn[0] == $booksAll[1]);
$this->assertTrue($booksIn[1] == $booksAll[2]);
// filter by min value with greater equal
$booksIn = null;
$booksIn = BookQuery::create()->filterById(['min' => $booksAll[2]->getId()])->find();
$this->assertTrue($booksIn[1] == $booksAll[3]);
// filter by max value with less equal
$booksIn = null;
$booksIn = BookQuery::create()->filterById(['max' => $booksAll[1]->getId()])->find();
$this->assertTrue($booksIn[1] == $booksAll[1]);
// check backwards compatibility:
// SELECT FROM `book` WHERE book.id IN (:p1,:p2)
// must be the same as
// SELECT FROM `book` WHERE (book.id>=:p1 AND book.id<=:p2)
$minMax = BookQuery::create()->filterById(['min' => $booksAll[1]->getId(), 'max' => $booksAll[2]->getId()])->find();
$In = BookQuery::create()->filterById([$booksAll[1]->getId(), $booksAll[2]->getId()])->find();
$this->assertTrue($minMax[0] === $In[0]);
$this->assertTrue(count($minMax->getData()) === count($In->getData()));
}
示例3: testMagicRequireOneWithAndThrowsException
public function testMagicRequireOneWithAndThrowsException()
{
$this->setExpectedException('\\Propel\\Runtime\\Exception\\EntityNotFoundException', 'Book could not be found');
BookQuery::create()->requireOneByTitleAndId('Not Existing Book', -1337);
}
示例4: testFindPkWithOneToMany
public function testFindPkWithOneToMany()
{
BookstoreDataPopulator::populate();
BookPeer::clearInstancePool();
AuthorPeer::clearInstancePool();
ReviewPeer::clearInstancePool();
$con = Propel::getServiceContainer()->getConnection(BookPeer::DATABASE_NAME);
$book = BookQuery::create()->findOneByTitle('Harry Potter and the Order of the Phoenix', $con);
$pk = $book->getPrimaryKey();
BookPeer::clearInstancePool();
$book = BookQuery::create()->setFormatter(ModelCriteria::FORMAT_ARRAY)->joinWith('Review')->findPk($pk, $con);
$reviews = $book['Reviews'];
$this->assertEquals(2, count($reviews), 'Related objects are correctly hydrated');
}
示例5: testDebugLog
public function testDebugLog()
{
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
// save data to return to normal state after test
$logger = $con->getLogger();
$logMethods = $con->getLogMethods();
$testLog = new Logger('debug');
$handler = new LastMessageHandler();
$testLog->pushHandler($handler);
$con->setLogger($testLog);
$con->setLogMethods(['exec', 'query', 'execute', 'beginTransaction', 'commit', 'rollBack']);
$con->useDebug(true);
$con->beginTransaction();
// test transaction log
$this->assertEquals('Begin transaction', $handler->latestMessage, 'PropelPDO logs begin transaction in debug mode');
$con->commit();
$this->assertEquals('Commit transaction', $handler->latestMessage, 'PropelPDO logs commit transaction in debug mode');
$con->beginTransaction();
$con->rollBack();
$this->assertEquals('Rollback transaction', $handler->latestMessage, 'PropelPDO logs rollback transaction in debug mode');
$con->beginTransaction();
$handler->latestMessage = '';
$con->beginTransaction();
$this->assertEquals('', $handler->latestMessage, 'PropelPDO does not log nested begin transaction in debug mode');
$con->commit();
$this->assertEquals('', $handler->latestMessage, 'PropelPDO does not log nested commit transaction in debug mode');
$con->beginTransaction();
$con->rollBack();
$this->assertEquals('', $handler->latestMessage, 'PropelPDO does not log nested rollback transaction in debug mode');
$con->rollback();
// test query log
$con->beginTransaction();
$c = new Criteria();
$c->add(BookTableMap::COL_TITLE, 'Harry%s', Criteria::LIKE);
$books = BookQuery::create(null, $c)->find($con);
$latestExecutedQuery = $this->getSql("SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM book WHERE book.title LIKE 'Harry%s'");
$this->assertEquals($latestExecutedQuery, $handler->latestMessage, 'PropelPDO logs queries and populates bound parameters in debug mode');
BookTableMap::doDeleteAll($con);
$latestExecutedQuery = $this->getSql("DELETE FROM book");
$this->assertEquals($latestExecutedQuery, $handler->latestMessage, 'PropelPDO logs deletion queries in debug mode');
$latestExecutedQuery = 'DELETE FROM book WHERE 1=1';
$con->exec($latestExecutedQuery);
$this->assertEquals($latestExecutedQuery, $handler->latestMessage, 'PropelPDO logs exec queries in debug mode');
$con->commit();
// return to normal state after test
$con->setLogger($logger);
$con->setLogMethods($logMethods);
}
示例6: testLobSetting_WriteMode
public function testLobSetting_WriteMode()
{
$blob_path = $this->getLobFile('tin_drum.gif');
$blob2_path = $this->getLobFile('propel.gif');
$clob_path = $this->getLobFile('tin_drum.txt');
$book = BookQuery::create()->findOne();
$m1 = new Media();
$m1->setBook($book);
$m1->setCoverImage(file_get_contents($blob_path));
$m1->setExcerpt(file_get_contents($clob_path));
$m1->save();
MediaTableMap::clearInstancePool();
// make sure we have the latest from the db:
$m2 = MediaQuery::create()->findPk($m1->getId());
// now attempt to assign a temporary stream, opened in 'w' mode, to the db
$stream = fopen("php://memory", 'w');
fwrite($stream, file_get_contents($blob2_path));
$m2->setCoverImage($stream);
$m2->save();
fclose($stream);
$m2->reload();
$this->assertEquals(md5(file_get_contents($blob2_path)), md5(stream_get_contents($m2->getCoverImage())), "Expected contents to match when setting stream w/ 'w' mode");
$stream2 = fopen("php://memory", 'w+');
fwrite($stream2, file_get_contents($blob_path));
rewind($stream2);
$this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($stream2)), "Expecting setup to be correct");
$m2->setCoverImage($stream2);
$m2->save();
$m2->reload();
$this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($m2->getCoverImage())), "Expected contents to match when setting stream w/ 'w+' mode");
}
示例7: testFindOneWithLeftJoinWithOneToManyAndNullObjectsAndWithAdditionalJoins
public function testFindOneWithLeftJoinWithOneToManyAndNullObjectsAndWithAdditionalJoins()
{
BookTableMap::clearInstancePool();
AuthorTableMap::clearInstancePool();
BookOpinionTableMap::clearInstancePool();
BookReaderTableMap::clearInstancePool();
$freud = new Author();
$freud->setFirstName("Sigmund");
$freud->setLastName("Freud");
$freud->save($this->con);
$publisher = new Publisher();
$publisher->setName('Psycho Books');
$publisher->save();
$book = new Book();
$book->setAuthor($freud);
$book->setTitle('Weirdness');
$book->setIsbn('abc123456');
$book->setPrice('14.99');
$book->setPublisher($publisher);
$book->save();
$query = BookQuery::create()->filterByTitle('Weirdness')->innerJoinAuthor()->useBookOpinionQuery(null, Criteria::LEFT_JOIN)->leftJoinBookReader()->endUse()->with('Author')->with('BookOpinion')->with('BookReader');
$books = $query->find($this->con)->get(0);
$this->assertEquals(0, count($books->getBookOpinions()));
}
示例8: testCountableInterface
public function testCountableInterface()
{
BookQuery::create()->deleteAll();
$pager = $this->getPager(10);
$this->assertCount(0, $pager);
$this->createBooks(15);
$pager = $this->getPager(10);
$this->assertCount(10, $pager);
$pager = $this->getPager(10, 2);
$this->assertCount(5, $pager);
}
示例9: testSubQueryWithJoin
public function testSubQueryWithJoin()
{
$c1 = BookQuery::create()->useAuthorQuery()->filterByLastName('Rowling')->endUse();
$c2 = new BookQuery();
$c2->addSelectQuery($c1, 'subQuery');
$c2->filterByPrice(20, Criteria::LESS_THAN);
$sql = $this->getSql("SELECT subQuery.id, subQuery.title, subQuery.isbn, subQuery.price, subQuery.publisher_id, subQuery.author_id FROM (SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM book LEFT JOIN author ON (book.author_id=author.id) WHERE author.last_name=:p2) AS subQuery WHERE subQuery.price<:p1");
$params = array(array('table' => 'book', 'column' => 'price', 'value' => 20), array('table' => 'author', 'column' => 'last_name', 'value' => 'Rowling'));
$this->assertCriteriaTranslation($c2, $sql, $params, 'addSelectQuery() can add a select query with a join');
}
示例10: testPopulateRelationManyToOne
public function testPopulateRelationManyToOne()
{
$con = Propel::getServiceContainer()->getReadConnection(BookTableMap::DATABASE_NAME);
AuthorTableMap::clearInstancePool();
BookTableMap::clearInstancePool();
$books = BookQuery::create()->find($con);
$count = $con->getQueryCount();
$books->populateRelation('Author', null, $con);
foreach ($books as $book) {
$author = $book->getAuthor();
}
$this->assertEquals($count + 1, $con->getQueryCount(), 'populateRelation() populates a many-to-one relationship with a single supplementary query');
}
示例11: testGroupBy
public function testGroupBy()
{
$params = [];
$c = BookQuery::create()->joinReview()->withColumn('COUNT(Review.id)', 'Count')->groupById();
$result = $c->createSelectSql($params);
if ($this->runningOnPostgreSQL()) {
$sql = 'SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id, COUNT(review.id) AS Count FROM book LEFT JOIN review ON (book.id=review.book_id) GROUP BY book.id,book.title,book.isbn,book.price,book.publisher_id,book.author_id';
} else {
$sql = $this->getSql('SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id, COUNT(review.id) AS Count FROM book LEFT JOIN review ON (book.id=review.book_id) GROUP BY book.id');
}
$this->assertEquals($sql, $result);
}
示例12: testRemoveObjectOneToManyWithFkRequired
public function testRemoveObjectOneToManyWithFkRequired()
{
BookSummaryQuery::create()->deleteAll();
BookQuery::create()->deleteAll();
$bookSummary = new BookSummary();
$bookSummary->setSummary('summary Propel Book');
$bookSummary2 = new BookSummary();
$bookSummary2->setSummary('summary2 Propel Book');
$book = new Book();
$book->setTitle('Propel Book');
$book->setISBN('01234');
$book->addBookSummary($bookSummary);
$book->addBookSummary($bookSummary2);
$this->assertCount(2, $book->getBookSummaries());
$book->removeBookSummary($bookSummary);
$bookSummaries = $book->getBookSummaries();
$this->assertCount(1, $bookSummaries);
$this->assertEquals('summary2 Propel Book', $bookSummaries->getFirst()->getSummary());
$book->save();
$bookSummary2->save();
$this->assertEquals(1, BookQuery::create()->count(), 'One Book');
$this->assertEquals(1, BookSummaryQuery::create()->count(), 'One Summary');
$this->assertEquals(1, BookSummaryQuery::create()->filterBySummarizedBook($book)->count());
$book->addBookSummary($bookSummary);
$bookSummary->save();
$book->save();
$this->assertEquals(2, BookSummaryQuery::create()->filterBySummarizedBook($book)->count());
$book->removeBookSummary($bookSummary2);
$book->save();
$this->assertEquals(1, BookSummaryQuery::create()->filterBySummarizedBook($book)->count());
$this->assertEquals(1, BookSummaryQuery::create()->count(), 'One Book summary because FK is required so book summary is deleted when book is saved');
}
示例13: testMagicFindByObject
public function testMagicFindByObject()
{
$con = Propel::getServiceContainer()->getConnection(BookPeer::DATABASE_NAME);
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Author');
$testAuthor = $c->findOne();
$q = BookQuery::create()->findByAuthor($testAuthor);
$expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` WHERE book.AUTHOR_ID=" . $testAuthor->getId();
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'findByXXX($value) is turned into findBy(XXX, $value)');
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Author');
$testAuthor = $c->findOne();
$q = BookQuery::create()->findByAuthorAndISBN($testAuthor, 1234);
$expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` WHERE book.AUTHOR_ID=" . $testAuthor->getId() . " AND book.ISBN=1234";
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'findByXXXAndYYY($value) is turned into findBy(array(XXX, YYY), $value)');
}
示例14: populateOpinionFavorite
public static function populateOpinionFavorite($con = null)
{
if ($con === null) {
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
}
$con->beginTransaction();
$book1 = BookQuery::create()->findOne($con);
$reader1 = new BookReader();
$reader1->save($con);
$bo = new BookOpinion();
$bo->setBook($book1);
$bo->setBookReader($reader1);
$bo->save($con);
$rf = new ReaderFavorite();
$rf->setBookOpinion($bo);
$rf->save($con);
$con->commit();
}
示例15: testCombineAndFilterBy
public function testCombineAndFilterBy()
{
$params = array();
$sql = "SELECT FROM book WHERE ((book.TITLE LIKE :p1 OR book.ISBN LIKE :p2) AND book.TITLE LIKE :p3)";
$c = BookQuery::create()->condition('u1', 'book.TITLE LIKE ?', '%test1%')->condition('u2', 'book.ISBN LIKE ?', '%test2%')->combine(array('u1', 'u2'), 'or')->filterByTitle('%test3%');
$result = $c->createSelectSql($params);
$this->assertEquals($sql, $result);
$params = array();
$sql = "SELECT FROM book WHERE (book.TITLE LIKE :p1 AND (book.TITLE LIKE :p2 OR book.ISBN LIKE :p3))";
$c = BookQuery::create()->filterByTitle('%test3%')->condition('u1', 'book.TITLE LIKE ?', '%test1%')->condition('u2', 'book.ISBN LIKE ?', '%test2%')->combine(array('u1', 'u2'), 'or');
$result = $c->createSelectSql($params);
$this->assertEquals($sql, $result);
}