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


PHP AuthorPeer::retrieveByPK方法代码示例

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


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

示例1: testNestedTransactionForceRollBack

 public function testNestedTransactionForceRollBack()
 {
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $driver = $con->getAttribute(PDO::ATTR_DRIVER_NAME);
     // main transaction
     $con->beginTransaction();
     $a = new Author();
     $a->setFirstName('Test');
     $a->setLastName('User');
     $a->save($con);
     $authorId = $a->getId();
     // nested transaction
     $con->beginTransaction();
     $a2 = new Author();
     $a2->setFirstName('Test2');
     $a2->setLastName('User2');
     $a2->save($con);
     $authorId2 = $a2->getId();
     // force rollback
     $con->forceRollback();
     $this->assertEquals(0, $con->getNestedTransactionCount(), 'nested transaction is null after nested transaction forced rollback');
     $this->assertFalse($con->isInTransaction(), 'PropelPDO is not in transaction after nested transaction force rollback');
     AuthorPeer::clearInstancePool();
     $at = AuthorPeer::retrieveByPK($authorId);
     $this->assertNull($at, "Rolled back transaction is not persisted in database");
     $at2 = AuthorPeer::retrieveByPK($authorId2);
     $this->assertNull($at2, "Forced Rolled back nested transaction is not persisted in database");
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:28,代码来源:PropelPDOTest.php

示例2: 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

示例3: getAuthor

 public function getAuthor($con = null)
 {
     include_once 'lib/model/om/BaseAuthorPeer.php';
     if ($this->aAuthor === null && $this->author_id !== null) {
         $this->aAuthor = AuthorPeer::retrieveByPK($this->author_id, $con);
     }
     return $this->aAuthor;
 }
开发者ID:valerio-bozzolan,项目名称:openparlamento,代码行数:8,代码来源:BaseAuthorArticle.php

示例4: testSavingParentSavesRelatedObjectsIncludingNew

 public function testSavingParentSavesRelatedObjectsIncludingNew()
 {
     $author = AuthorPeer::retrieveByPK($this->author->getId());
     // add new object before fetching old books
     $b3 = new Book();
     $author->addBook($b3);
     $c = new Criteria();
     $c->add(BookPeer::ID, $this->books[0]->getId());
     $books = $author->getBooks($c);
     $books[0]->setTitle('Update to a book');
     $author->save();
     $this->assertEquals(3, $author->countBooks());
     $this->assertFalse($b3->isModified());
     $this->assertFalse($books[0]->isModified());
 }
开发者ID:kcornejo,项目名称:estadistica,代码行数:15,代码来源:PoisonedCacheBugTest.php

示例5: testRollBack_NestedSwallow

 /**
  * @link       http://propel.phpdb.org/trac/ticket/699
  */
 public function testRollBack_NestedSwallow()
 {
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $driver = $con->getAttribute(PDO::ATTR_DRIVER_NAME);
     if ($driver == "mysql") {
         $this->markTestSkipped();
     }
     $con->beginTransaction();
     try {
         $a = new Author();
         $a->setFirstName('Test');
         $a->setLastName('User');
         $a->save($con);
         $authorId = $a->getId();
         $this->assertTrue($authorId !== null, "Expected valid new author ID");
         $con->beginTransaction();
         try {
             $con->exec('INVALID SQL');
             $this->fail("Expected exception on invalid SQL");
         } catch (Exception $x) {
             $con->rollBack();
             // NO RETHROW
         }
         $a2 = new Author();
         $a2->setFirstName('Test2');
         $a2->setLastName('User2');
         $authorId2 = $a2->save($con);
         $con->commit();
         // this should not do anything!
     } catch (Exception $x) {
         $this->fail("No outside rollback expected.");
     }
     AuthorPeer::clearInstancePool();
     $at = AuthorPeer::retrieveByPK($authorId);
     $this->assertNull($at, "Expected no author result for rolled-back save.");
     $at2 = AuthorPeer::retrieveByPK($authorId2);
     $this->assertNull($at2, "Expected no author2 result for rolled-back save.");
 }
开发者ID:JimmyVB,项目名称:Symfony-v1.2,代码行数:41,代码来源:PropelPDOTest.php

示例6: getAuthor

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


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