当前位置: 首页>>代码示例>>PHP>>正文


PHP BookQuery::create方法代码示例

本文整理汇总了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));
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:11,代码来源:ActiveRecordSerializeTest.php

示例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()));
 }
开发者ID:eat24,项目名称:propel,代码行数:37,代码来源:PropelQueryTest.php

示例3: testMagicRequireOneWithAndThrowsException

 public function testMagicRequireOneWithAndThrowsException()
 {
     $this->setExpectedException('\\Propel\\Runtime\\Exception\\EntityNotFoundException', 'Book could not be found');
     BookQuery::create()->requireOneByTitleAndId('Not Existing Book', -1337);
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:5,代码来源:ModelCriteriaTest.php

示例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');
 }
开发者ID:rouffj,项目名称:Propel2,代码行数:14,代码来源:ArrayFormatterWithTest.php

示例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);
 }
开发者ID:disider,项目名称:Propel2,代码行数:48,代码来源:PropelPDOTest.php

示例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");
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:31,代码来源:GeneratedObjectLobTest.php

示例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()));
 }
开发者ID:disider,项目名称:Propel2,代码行数:24,代码来源:ObjectFormatterWithTest.php

示例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);
 }
开发者ID:bondarovich,项目名称:Propel2,代码行数:11,代码来源:PropelModelPagerTest.php

示例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');
 }
开发者ID:KyleGoslan,项目名称:Huge-Propel,代码行数:10,代码来源:SubQueryTest.php

示例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');
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:13,代码来源:ObjectCollectionWithFixturesTest.php

示例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);
 }
开发者ID:naldz,项目名称:cyberden,代码行数:12,代码来源:CriteriaTest.php

示例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');
 }
开发者ID:disider,项目名称:Propel2,代码行数:32,代码来源:GeneratedObjectRelTest.php

示例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)');
 }
开发者ID:rozwell,项目名称:Propel2,代码行数:14,代码来源:ModelCriteriaTest.php

示例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();
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:18,代码来源:BookstoreDataPopulator.php

示例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);
 }
开发者ID:robin850,项目名称:Propel2,代码行数:13,代码来源:CriteriaTest.php


注:本文中的Propel\Tests\Bookstore\BookQuery::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。