本文整理汇总了PHP中ModelCriteria::count方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelCriteria::count方法的具体用法?PHP ModelCriteria::count怎么用?PHP ModelCriteria::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelCriteria
的用法示例。
在下文中一共展示了ModelCriteria::count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPreDelete
public function testPreDelete()
{
$c = new ModelCriteria('bookstore', 'Book');
$books = $c->find();
$count = count($books);
$book = $books->shift();
$c = new ModelCriteriaWithPreDeleteHook('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', 'Book');
$nbBooks = $c->count();
$this->assertEquals($count, $nbBooks, 'preDelete() can bypass the row deletion');
$c = new ModelCriteriaWithPreDeleteHook('bookstore', 'Book');
$nbBooks = $c->deleteAll();
$this->assertEquals(12, $nbBooks, 'preDelete() can change the return value of deleteAll()');
$c = new ModelCriteria('bookstore', 'Book');
$nbBooks = $c->count();
$this->assertEquals($count, $nbBooks, 'preDelete() can bypass the row deletion');
}
示例2: testUpdateOneByOne
public function testUpdateOneByOne()
{
$con = Propel::getConnection(BookPeer::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', 'Book');
$books = $c->find();
foreach ($books as $book) {
$book->save();
}
$count = $con->getQueryCount();
$c = new ModelCriteria('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', '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', 'Book');
$books = $c->find();
foreach ($books as $book) {
$book->save();
}
$count = $con->getQueryCount();
$c = new ModelCriteria('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', 'Book', 'b');
$c->where('b.Title = ?', 'Don Juan');
$book = $c->findOne();
$this->assertEquals('3456', $book->getISBN(), 'update() updates only the records matching the criteria');
}