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


PHP ModelCriteria::count方法代码示例

本文整理汇总了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');
 }
开发者ID:kcornejo,项目名称:estadistica,代码行数:20,代码来源:ModelCriteriaHooksTest.php

示例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');
 }
开发者ID:ketheriel,项目名称:ETVA,代码行数:39,代码来源:ModelCriteriaTest.php


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