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


PHP BookPeer::retrieveByPK方法代码示例

本文整理汇总了PHP中BookPeer::retrieveByPK方法的典型用法代码示例。如果您正苦于以下问题:PHP BookPeer::retrieveByPK方法的具体用法?PHP BookPeer::retrieveByPK怎么用?PHP BookPeer::retrieveByPK使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BookPeer的用法示例。


在下文中一共展示了BookPeer::retrieveByPK方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testPoisonedCacheWhenSavingABook

 public function testPoisonedCacheWhenSavingABook()
 {
     $b1 = BookPeer::retrieveByPK($this->books[0]->getId());
     // if author is loaded then doSave will do addBook($b1) and poison the authors books cache
     $b1->getAuthor();
     // e.g. to update viewed count etc
     $b1->save();
     // ... later down the line fetch the author
     $author = AuthorPeer::retrieveByPK($this->author->getId());
     $this->assertEquals(2, count($author->getBooks()));
     $this->assertEquals(2, $author->countBooks());
 }
开发者ID:kcornejo,项目名称:estadistica,代码行数:12,代码来源:PoisonedCacheBugTest.php

示例2: testDelete

 /**
  * Test deleting an object using the delete() method.
  */
 public function testDelete()
 {
     BookstoreDataPopulator::populate();
     // 1) grab an arbitrary object
     $book = BookPeer::doSelectOne(new Criteria());
     $bookId = $book->getId();
     // 2) delete it
     $book->delete();
     // 3) make sure it can't be save()d now that it's deleted
     try {
         $book->setTitle("Will Fail");
         $book->save();
         $this->fail("Expect an exception to be thrown when attempting to save() a deleted object.");
     } catch (PropelException $e) {
     }
     // 4) make sure that it doesn't exist in db
     $book = BookPeer::retrieveByPK($bookId);
     $this->assertNull($book, "Expect NULL from retrieveByPK on deleted Book.");
 }
开发者ID:ketheriel,项目名称:ETVA,代码行数:22,代码来源:GeneratedObjectWithFixturesTest.php

示例3: testCountRefFk

 public function testCountRefFk()
 {
     $book = new Book();
     $book->setTitle("Test Book");
     $book->setISBN("TT-EE-SS-TT");
     $num = 5;
     for ($i = 2; $i < $num + 2; $i++) {
         $r = new Review();
         $r->setReviewedBy('Hans ' . $num);
         $dt = new DateTime("now");
         $dt->modify("-" . $i . " weeks");
         $r->setReviewDate($dt);
         $r->setRecommended($i % 2 == 0);
         $book->addReview($r);
     }
     $this->assertEquals($num, $book->countReviews(), "Expected countReviews to return {$num}");
     $this->assertEquals($num, count($book->getReviews()), "Expected getReviews to return {$num} reviews");
     $book->save();
     BookPeer::clearInstancePool();
     ReviewPeer::clearInstancePool();
     $book = BookPeer::retrieveByPK($book->getId());
     $this->assertEquals($num, $book->countReviews(), "Expected countReviews() to return {$num} (after save)");
     $this->assertEquals($num, count($book->getReviews()), "Expected getReviews() to return {$num} (after save)");
     // Now set different criteria and expect different results
     $c = new Criteria();
     $c->add(ReviewPeer::RECOMMENDED, false);
     $this->assertEquals(floor($num / 2), $book->countReviews($c), "Expected " . floor($num / 2) . " results from countReviews(recomm=false)");
     // Change Criteria, run again -- expect different.
     $c = new Criteria();
     $c->add(ReviewPeer::RECOMMENDED, true);
     $this->assertEquals(ceil($num / 2), count($book->getReviews($c)), "Expected " . ceil($num / 2) . " results from getReviews(recomm=true)");
     $this->assertEquals($num, $book->countReviews(), "Expected countReviews to return {$num} with new empty Criteria");
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:33,代码来源:GeneratedObjectTest.php

示例4: testObjectInstances

 public function testObjectInstances()
 {
     $sample = BookPeer::doSelectOne(new Criteria());
     $samplePk = $sample->getPrimaryKey();
     // 1) make sure consecutive calls to retrieveByPK() return the same object.
     $b1 = BookPeer::retrieveByPK($samplePk);
     $b2 = BookPeer::retrieveByPK($samplePk);
     $sampleval = md5(microtime());
     $this->assertTrue($b1 === $b2, "Expected object instances to match for calls with same retrieveByPK() method signature.");
     // 2) make sure that calls to doSelect also return references to the same objects.
     $allbooks = BookPeer::doSelect(new Criteria());
     foreach ($allbooks as $testb) {
         if ($testb->getPrimaryKey() == $b1->getPrimaryKey()) {
             $this->assertTrue($testb === $b1, "Expected same object instance from doSelect() as from retrieveByPK()");
         }
     }
     // 3) test fetching related objects
     $book = BookPeer::retrieveByPK($samplePk);
     $bookauthor = $book->getAuthor();
     $author = AuthorPeer::retrieveByPK($bookauthor->getId());
     $this->assertTrue($bookauthor === $author, "Expected same object instance when calling fk object accessor as retrieveByPK()");
     // 4) test a doSelectJoin()
     $morebooks = BookPeer::doSelectJoinAuthor(new Criteria());
     for ($i = 0, $j = 0; $j < count($morebooks); $i++, $j++) {
         $testb1 = $allbooks[$i];
         $testb2 = $allbooks[$j];
         $this->assertTrue($testb1 === $testb2, "Expected the same objects from consecutive doSelect() calls.");
         // we could probably also test this by just verifying that $book & $testb are the same
         if ($testb1->getPrimaryKey() === $book) {
             $this->assertTrue($book->getAuthor() === $testb1->getAuthor(), "Expected same author object in calls to pkey-matching books.");
         }
     }
     // 5) test creating a new object, saving it, and then retrieving that object (should all be same instance)
     $b = new BookstoreEmployee();
     $b->setName("Testing");
     $b->setJobTitle("Testing");
     $b->save();
     $empId = $b->getId();
     $this->assertSame($b, BookstoreEmployeePeer::retrieveByPK($empId), "Expected newly saved object to be same instance as pooled.");
 }
开发者ID:RafalFilipek,项目名称:Propel2,代码行数:40,代码来源:GeneratedPeerDoSelectTest.php

示例5: createBookWithId

 /**
  * @see        testDoDeleteCompositePK()
  */
 private function createBookWithId($id)
 {
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $b = BookPeer::retrieveByPK($id);
     if (!$b) {
         $b = new Book();
         $b->setTitle("Book{$id}")->setISBN("BookISBN{$id}")->save();
         $b1Id = $b->getId();
         $sql = "UPDATE " . BookPeer::TABLE_NAME . " SET id = ? WHERE id = ?";
         $stmt = $con->prepare($sql);
         $stmt->bindValue(1, $id);
         $stmt->bindValue(2, $b1Id);
         $stmt->execute();
     }
 }
开发者ID:ketheriel,项目名称:ETVA,代码行数:18,代码来源:GeneratedPeerDoDeleteTest.php

示例6: getBook

 public function getBook($con = null)
 {
     include_once 'lib/model/om/BaseBookPeer.php';
     if ($this->aBook === null && $this->book_id !== null) {
         $this->aBook = BookPeer::retrieveByPK($this->book_id, $con);
     }
     return $this->aBook;
 }
开发者ID:valerio-bozzolan,项目名称:openparlamento,代码行数:8,代码来源:BaseArticle.php

示例7: getBook

 public function getBook($con = null)
 {
     if ($this->aBook === null && $this->book_id !== null) {
         $this->aBook = BookPeer::retrieveByPK($this->book_id, $con);
     }
     return $this->aBook;
 }
开发者ID:ajith24,项目名称:ajithworld,代码行数:7,代码来源:BaseArticle.php


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