本文整理匯總了PHP中Propel\Runtime\ActiveQuery\ModelCriteria::count方法的典型用法代碼示例。如果您正苦於以下問題:PHP ModelCriteria::count方法的具體用法?PHP ModelCriteria::count怎麽用?PHP ModelCriteria::count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Propel\Runtime\ActiveQuery\ModelCriteria
的用法示例。
在下文中一共展示了ModelCriteria::count方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testPreDelete
public function testPreDelete()
{
$c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
$books = $c->find();
$count = count($books);
$book = $books->shift();
$c = new ModelCriteriaWithPreDeleteHook('bookstore', '\\Propel\\Tests\\Bookstore\\Book', 'b');
$c->where('b.Id = ?', $book->getId());
$nbBooks = $c->delete();
$this->assertEquals(12, $nbBooks, 'preDelete() can change the return value of delete()');
$c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
$nbBooks = $c->count();
$this->assertEquals($count, $nbBooks, 'preDelete() can bypass the row deletion');
$c = new ModelCriteriaWithPreDeleteHook('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
$nbBooks = $c->deleteAll();
$this->assertEquals(12, $nbBooks, 'preDelete() can change the return value of deleteAll()');
$c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
$nbBooks = $c->count();
$this->assertEquals($count, $nbBooks, 'preDelete() can bypass the row deletion');
}
示例2: testUpdateOneByOne
public function testUpdateOneByOne()
{
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
BookstoreDataPopulator::depopulate($con);
BookstoreDataPopulator::populate($con);
// save all books to make sure related objects are also saved - BookstoreDataPopulator keeps some unsaved
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$books = $c->find();
foreach ($books as $book) {
$book->save();
}
$count = $con->getQueryCount();
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$nbBooks = $c->update(array('Title' => 'foo'), $con, true);
$this->assertEquals(4, $nbBooks, 'update() returns the number of updated rows');
$this->assertEquals($count + 1 + 4, $con->getQueryCount(), 'update() updates the objects one by one when called with true as last parameter');
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book', 'b');
$c->where('b.Title = ?', 'foo');
$nbBooks = $c->count();
$this->assertEquals(4, $nbBooks, 'update() updates all records by default');
BookstoreDataPopulator::depopulate($con);
BookstoreDataPopulator::populate($con);
// save all books to make sure related objects are also saved - BookstoreDataPopulator keeps some unsaved
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$books = $c->find();
foreach ($books as $book) {
$book->save();
}
$count = $con->getQueryCount();
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book', 'b');
$c->where('b.Title = ?', 'Don Juan');
$nbBooks = $c->update(array('ISBN' => '3456'), $con, true);
$this->assertEquals(1, $nbBooks, 'update() updates only the records matching the criteria');
$this->assertEquals($count + 1 + 1, $con->getQueryCount(), 'update() updates the objects one by one when called with true as last parameter');
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book', 'b');
$c->where('b.Title = ?', 'Don Juan');
$book = $c->findOne();
$this->assertEquals('3456', $book->getISBN(), 'update() updates only the records matching the criteria');
}