本文整理汇总了PHP中BookPeer::clearInstancePool方法的典型用法代码示例。如果您正苦于以下问题:PHP BookPeer::clearInstancePool方法的具体用法?PHP BookPeer::clearInstancePool怎么用?PHP BookPeer::clearInstancePool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BookPeer
的用法示例。
在下文中一共展示了BookPeer::clearInstancePool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
/**
* This is run after each unit test. It empties the database.
*/
protected function tearDown()
{
BookstoreDataPopulator::depopulate();
$this->assertEquals(0, count(BookPeer::doSelect(new Criteria())), "Expect book table to be empty.");
$this->assertEquals(0, count(AuthorPeer::doSelect(new Criteria())), "Expect author table to be empty.");
$this->assertEquals(0, count(PublisherPeer::doSelect(new Criteria())), "Expect publisher table to be empty.");
$this->assertEquals(0, count(ReviewPeer::doSelect(new Criteria())), "Expect review table to be empty.");
$this->assertEquals(0, count(MediaPeer::doSelect(new Criteria())), "Expect media table to be empty.");
$this->assertEquals(0, count(BookstoreEmployeePeer::doSelect(new Criteria())), "Expect bookstore_employee table to be empty.");
$this->assertEquals(0, count(BookstoreEmployeeAccountPeer::doSelect(new Criteria())), "Expect bookstore_employee_account table to be empty.");
$this->assertEquals(0, count(BookstoreSalePeer::doSelect(new Criteria())), "Expect bookstore_sale table to be empty.");
BookPeer::clearInstancePool();
$this->assertEquals(0, count(BookPeer::$instances), "Expected 0 Book instances after clearInstancePool()");
AuthorPeer::clearInstancePool();
$this->assertEquals(0, count(AuthorPeer::$instances), "Expected 0 Author instances after clearInstancePool()");
PublisherPeer::clearInstancePool();
$this->assertEquals(0, count(PublisherPeer::$instances), "Expected 0 Publisher instances after clearInstancePool()");
ReviewPeer::clearInstancePool();
$this->assertEquals(0, count(ReviewPeer::$instances), "Expected 0 Review instances after clearInstancePool()");
MediaPeer::clearInstancePool();
$this->assertEquals(0, count(MediaPeer::$instances), "Expected 0 Media instances after clearInstancePool()");
BookstoreEmployeePeer::clearInstancePool();
$this->assertEquals(0, count(BookstoreEmployeePeer::$instances), "Expected 0 BookstoreEmployee instances after clearInstancePool()");
BookstoreEmployeeAccountPeer::clearInstancePool();
$this->assertEquals(0, count(BookstoreEmployeeAccountPeer::$instances), "Expected 0 BookstoreEmployeeAccount instances after clearInstancePool()");
BookstoreSalePeer::clearInstancePool();
$this->assertEquals(0, count(BookstoreSalePeer::$instances), "Expected 0 BookstoreSale instances after clearInstancePool()");
parent::tearDown();
}
示例2: testDelete
public function testDelete()
{
$books = PropelQuery::from('Book')->setFormatter(ModelCriteria::FORMAT_ARRAY)->find();
$books->delete();
// check that the modifications are persisted
BookPeer::clearInstancePool();
$books = PropelQuery::from('Book')->find();
$this->assertEquals(0, count($books));
}
示例3: testSerializeHydratedObject
public function testSerializeHydratedObject()
{
$book = new Book();
$book->setTitle('Foo3');
$book->setISBN('1234');
$book->save();
BookPeer::clearInstancePool();
$book = BookQuery::create()->findOneByTitle('Foo3');
$sb = serialize($book);
$this->assertEquals($book, unserialize($sb));
}
示例4: 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");
}
示例5: testPruneCompositeKey
public function testPruneCompositeKey()
{
BookstoreDataPopulator::depopulate();
BookstoreDataPopulator::populate();
// save all books to make sure related objects are also saved - BookstoreDataPopulator keeps some unsaved
$c = new ModelCriteria('bookstore', 'Book');
$books = $c->find();
foreach ($books as $book) {
$book->save();
}
BookPeer::clearInstancePool();
$nbBookListRel = BookListRelQuery::create()->prune()->count();
$this->assertEquals(2, $nbBookListRel, 'prune() does nothing when passed a null object');
$testBookListRel = BookListRelQuery::create()->findOne();
$nbBookListRel = BookListRelQuery::create()->prune($testBookListRel)->count();
$this->assertEquals(1, $nbBookListRel, 'prune() removes an object from the result');
}
示例6: testDoSelectJoin_NullFk
/**
* Test the doSelectJoin*() methods when the related object is NULL.
*/
public function testDoSelectJoin_NullFk()
{
$b1 = new Book();
$b1->setTitle("Test NULLFK 1");
$b1->setISBN("NULLFK-1");
$b1->save();
$b2 = new Book();
$b2->setTitle("Test NULLFK 2");
$b2->setISBN("NULLFK-2");
$b2->setAuthor(new Author());
$b2->getAuthor()->setFirstName("Hans")->setLastName("L");
$b2->save();
BookPeer::clearInstancePool();
AuthorPeer::clearInstancePool();
$c = new Criteria();
$c->add(BookPeer::ISBN, 'NULLFK-%', Criteria::LIKE);
$c->addAscendingOrderByColumn(BookPeer::ISBN);
$matches = BookPeer::doSelectJoinAuthor($c);
$this->assertEquals(2, count($matches), "Expected 2 matches back from new books; got back " . count($matches));
$this->assertNull($matches[0]->getAuthor(), "Expected first book author to be null");
$this->assertInstanceOf('Author', $matches[1]->getAuthor(), "Expected valid Author object for second book.");
}
示例7: clearCache
function clearCache()
{
BookPeer::clearInstancePool();
AuthorPeer::clearInstancePool();
}
示例8: doDelete
/**
* Performs a DELETE on the database, given a Book or Criteria object OR a primary key value.
*
* @param mixed $values Criteria or Book object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param PropelPDO $con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doDelete($values, PropelPDO $con = null)
{
if ($con === null) {
$con = Propel::getConnection(BookPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
if ($values instanceof Criteria) {
// rename for clarity
$criteria = clone $values;
} elseif ($values instanceof Book) {
// it's a model object
// create criteria based on pk values
$criteria = $values->buildPkeyCriteria();
} else {
// it's a primary key, or an array of pks
$criteria = new Criteria(self::DATABASE_NAME);
$criteria->add(BookPeer::ID, (array) $values, Criteria::IN);
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
$affectedRows = 0;
// initialize var to track total num of affected rows
try {
// use transaction because $criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
$con->beginTransaction();
// cloning the Criteria in case it's modified by doSelect() or doSelectStmt()
$c = clone $criteria;
BookPeer::doOnDeleteSetNull($c, $con);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
if ($values instanceof Criteria) {
BookPeer::clearInstancePool();
} elseif ($values instanceof Book) {
// it's a model object
BookPeer::removeInstanceFromPool($values);
} else {
// it's a primary key, or an array of pks
foreach ((array) $values as $singleval) {
BookPeer::removeInstanceFromPool($singleval);
}
}
$affectedRows += BasePeer::doDelete($criteria, $con);
BookPeer::clearRelatedInstancePool();
$con->commit();
return $affectedRows;
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
示例9: testPopulateRelationManyToOne
public function testPopulateRelationManyToOne()
{
$con = Propel::getConnection();
AuthorPeer::clearInstancePool();
BookPeer::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');
}
示例10: testSetterOneToManyWithExistingObjects
public function testSetterOneToManyWithExistingObjects()
{
// Ensure no data
BookQuery::create()->deleteAll();
AuthorQuery::create()->deleteAll();
for ($i = 0; $i < 3; $i++) {
$b = new Book();
$b->setTitle('Book ' . $i);
$b->setIsbn('21234' . $i);
$b->save();
}
BookPeer::clearInstancePool();
$books = BookQuery::create()->find();
$a = new Author();
$a->setFirstName('Foo');
$a->setLastName('Bar');
$a->setBooks($books);
$a->save();
$this->assertEquals(3, count($a->getBooks()));
$this->assertEquals(1, AuthorQuery::create()->count());
$this->assertEquals(3, BookQuery::create()->count());
$i = 0;
foreach ($a->getBooks() as $book) {
$this->assertEquals('Book ' . $i++, $book->getTitle());
}
}
示例11: testPopulateRelationOneToManyWithEmptyCollection
public function testPopulateRelationOneToManyWithEmptyCollection()
{
$author = new Author();
$author->setLastName('I who never wrote');
$author->save($this->con);
AuthorPeer::clearInstancePool();
BookPeer::clearInstancePool();
$coll = new PropelObjectCollection();
$coll->setFormatter(new PropelObjectFormatter(new ModelCriteria(null, 'Author')));
$coll[] = $author;
$books = $coll->populateRelation('Book', null, $this->con);
$this->assertEquals(0, $books->count());
$count = $this->con->getQueryCount();
$this->assertEquals(0, $author->countBooks());
$this->assertEquals($count, $this->con->getQueryCount());
}
示例12: testSetterCollectionWithExistingObjects
public function testSetterCollectionWithExistingObjects()
{
// Ensure no data
BookQuery::create()->deleteAll();
BookClubListQuery::create()->deleteAll();
BookListRelQuery::create()->deleteAll();
for ($i = 0; $i < 3; $i++) {
$b = new Book();
$b->setTitle('Book ' . $i);
$b->save();
}
BookPeer::clearInstancePool();
$books = BookQuery::create()->find();
$bookClubList = new BookClubList();
$bookClubList->setBooks($books);
$bookClubList->save();
$this->assertEquals(3, count($bookClubList->getBooks()));
$this->assertEquals(3, BookQuery::create()->count());
$this->assertEquals(1, BookClubListQuery::create()->count());
$this->assertEquals(3, BookListRelQuery::create()->count());
$i = 0;
foreach ($bookClubList->getBooks() as $book) {
$this->assertEquals('Book ' . $i++, $book->getTitle());
}
}
示例13: clearRelatedInstancePool
/**
* Method to invalidate the instance pool of all tables related to author
* by a foreign key with ON DELETE CASCADE
*/
public static function clearRelatedInstancePool()
{
// Invalidate objects in BookPeer instance pool,
// since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
BookPeer::clearInstancePool();
}
示例14: testRefIsOnlySavedWhenRequired
public function testRefIsOnlySavedWhenRequired()
{
BookQuery::create()->deleteAll();
$book = new Book();
$book->setTitle('Propel Book');
$book->setISBN('TEST');
$book->save();
$bookId = $book->getId();
BookPeer::clearInstancePool();
$summary = $this->getMock('BookSummary');
$summary->expects($this->once())->method('isDeleted')->will($this->returnValue(false));
$summary->expects($this->once())->method('isNew')->will($this->returnValue(false));
$summary->expects($this->once())->method('isModified')->will($this->returnValue(false));
$summary->expects($this->never())->method('save');
$coll = new PropelObjectCollection();
$coll->append($summary);
$book = BookQuery::create()->findOneById($bookId);
// In conjunction with the mock above, this simulates loading those entries prior saving the book.
$book->setBookSummarys($coll);
$book->setTitle('Propel2 Book');
$book->save();
}
示例15: testFindOneWithLeftJoinWithOneToManyAndNullObjectsAndWithAdditionalJoins
public function testFindOneWithLeftJoinWithOneToManyAndNullObjectsAndWithAdditionalJoins()
{
BookPeer::clearInstancePool();
AuthorPeer::clearInstancePool();
BookOpinionPeer::clearInstancePool();
BookReaderPeer::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->findOne($this->con);
$this->assertEquals(0, count($books->getBookOpinions()));
}