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


PHP ModelCriteria::find方法代码示例

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


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

示例1: getCollection

 /**
  * Execute query, store result and return it.
  *
  * @return PropelCollection
  */
 protected function getCollection()
 {
     if ($this->collection === null) {
         $this->collection = $this->query->find();
     }
     return $this->collection;
 }
开发者ID:bombayworks,项目名称:currycms,代码行数:12,代码来源:QueryWrapper.php

示例2: testPreAndPostDelete

 public function testPreAndPostDelete()
 {
     $c = new ModelCriteria('bookstore', 'Book');
     $books = $c->find();
     $count = count($books);
     $book = $books->shift();
     $this->con->lastAffectedRows = 0;
     $c = new ModelCriteriaWithPreAndPostDeleteHook('bookstore', 'Book', 'b');
     $c->where('b.Id = ?', $book->getId());
     $nbBooks = $c->delete($this->con);
     $this->assertEquals(12, $this->con->lastAffectedRows, 'postDelete() is called after delete() even if preDelete() returns not null');
     $this->con->lastAffectedRows = 0;
     $c = new ModelCriteriaWithPreAndPostDeleteHook('bookstore', 'Book');
     $nbBooks = $c->deleteAll($this->con);
     $this->assertEquals(12, $this->con->lastAffectedRows, 'postDelete() is called after deleteAll() even if preDelete() returns not null');
 }
开发者ID:kcornejo,项目名称:estadistica,代码行数:16,代码来源:ModelCriteriaHooksTest.php

示例3: load

 /**
  * Loads the complete choice list entries, once.
  *
  * If data has been loaded the choice list is initialized with the retrieved data.
  */
 private function load()
 {
     if ($this->loaded) {
         return;
     }
     $models = (array) $this->query->find();
     $preferred = array();
     if ($this->preferredQuery instanceof \ModelCriteria) {
         $preferred = (array) $this->preferredQuery->find();
     }
     try {
         // The second parameter $labels is ignored by ObjectChoiceList
         parent::initialize($models, array(), $preferred);
         $this->loaded = true;
     } catch (StringCastException $e) {
         throw new StringCastException(str_replace('argument $labelPath', 'option "property"', $e->getMessage()), null, $e);
     }
 }
开发者ID:nibsirahsieu,项目名称:propel1-bridge,代码行数:23,代码来源:ModelChoiceList.php

示例4: testFindWithLeftJoinWithManyToOneAndNullObject

 public function testFindWithLeftJoinWithManyToOneAndNullObject()
 {
     BookPeer::clearInstancePool();
     AuthorPeer::clearInstancePool();
     ReviewPeer::clearInstancePool();
     $review = new Review();
     $review->save($this->con);
     $c = new ModelCriteria('bookstore', 'Review');
     $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $c->leftJoinWith('Review.Book');
     $c->leftJoinWith('Book.Author');
     // should not raise a notice
     $reviews = $c->find($this->con);
     $this->assertTrue(true);
 }
开发者ID:keneanung,项目名称:gw2spidy,代码行数:15,代码来源:PropelArrayFormatterWithTest.php

示例5: testFindOneWithOneToManyThenManyToOneUsingAlias

 public function testFindOneWithOneToManyThenManyToOneUsingAlias()
 {
     BookstoreDataPopulator::populate();
     BookPeer::clearInstancePool();
     AuthorPeer::clearInstancePool();
     ReviewPeer::clearInstancePool();
     $c = new ModelCriteria('bookstore', 'Author');
     $c->add(AuthorPeer::LAST_NAME, 'Rowling');
     $c->leftJoinWith('Author.Book b');
     $c->leftJoinWith('b.Review r');
     $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $authors = $c->find($con);
     $this->assertEquals(1, count($authors), 'with() does not duplicate the main object');
     $rowling = $authors[0];
     $this->assertEquals($rowling['FirstName'], 'J.K.', 'Main object is correctly hydrated');
     $books = $rowling['Books'];
     $this->assertEquals(1, count($books), 'Related objects are correctly hydrated');
     $book = $books[0];
     $this->assertEquals($book['Title'], 'Harry Potter and the Order of the Phoenix', 'Related object is correctly hydrated');
     $reviews = $book['Reviews'];
     $this->assertEquals(2, count($reviews), 'Related objects are correctly hydrated');
 }
开发者ID:RadioCampusFrance,项目名称:airtime,代码行数:23,代码来源:PropelArrayFormatterWithTest.php

示例6: testFindOneWithClassAndColumn

 public function testFindOneWithClassAndColumn()
 {
     BookstoreDataPopulator::populate();
     BookPeer::clearInstancePool();
     AuthorPeer::clearInstancePool();
     ReviewPeer::clearInstancePool();
     $c = new ModelCriteria('bookstore', 'Book');
     $c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
     $c->filterByTitle('The Tin Drum');
     $c->join('Book.Author');
     $c->withColumn('Author.FirstName', 'AuthorName');
     $c->withColumn('Author.LastName', 'AuthorName2');
     $c->with('Author');
     $c->limit(1);
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $books = $c->find($con);
     foreach ($books as $book) {
         break;
     }
     $this->assertTrue($book instanceof Book, 'withColumn() do not change the resulting model class');
     $this->assertEquals('The Tin Drum', $book->getTitle());
     $this->assertTrue($book->getAuthor() instanceof Author, 'PropelObjectFormatter correctly hydrates with class');
     $this->assertEquals('Gunter', $book->getAuthor()->getFirstName(), 'PropelObjectFormatter correctly hydrates with class');
     $this->assertEquals('Gunter', $book->getVirtualColumn('AuthorName'), 'PropelObjectFormatter adds withColumns as virtual columns');
     $this->assertEquals('Grass', $book->getVirtualColumn('AuthorName2'), 'PropelObjectFormatter correctly hydrates all virtual columns');
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:26,代码来源:PropelOnDemandFormatterWithTest.php

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

示例8: 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');
 }
开发者ID:shelsonjava,项目名称:datawrapper,代码行数:17,代码来源:QueryBuilderTest.php

示例9: testSelectArrayWithColumn

 public function testSelectArrayWithColumn()
 {
     BookstoreDataPopulator::depopulate($this->con);
     BookstoreDataPopulator::populate($this->con);
     $c = new ModelCriteria('bookstore', 'Book');
     $c->join('Book.Author');
     $c->withColumn('LOWER(Book.Title)', 'LowercaseTitle');
     $c->select(array('LowercaseTitle', 'Book.Title'));
     $c->orderBy('Book.Title');
     $rows = $c->find($this->con);
     $expectedSQL = 'SELECT LOWER(book.TITLE) AS LowercaseTitle, book.TITLE AS "Book.Title" FROM `book` INNER JOIN `author` ON (book.AUTHOR_ID=author.ID) ORDER BY book.TITLE ASC';
     $this->assertEquals($expectedSQL, $this->con->getLastExecutedQuery(), 'find() called after select(array) can cope with a column added with withColumn()');
     $expectedRows = array(array('LowercaseTitle' => 'don juan', 'Book.Title' => 'Don Juan'), array('LowercaseTitle' => 'harry potter and the order of the phoenix', 'Book.Title' => 'Harry Potter and the Order of the Phoenix'), array('LowercaseTitle' => 'quicksilver', 'Book.Title' => 'Quicksilver'), array('LowercaseTitle' => 'the tin drum', 'Book.Title' => 'The Tin Drum'));
     $this->assertEquals(serialize($rows->getData()), serialize($expectedRows), 'find() called after select(array) can cope with a column added with withColumn()');
 }
开发者ID:rubensayshi,项目名称:propelsandbox,代码行数:15,代码来源:ModelCriteriaSelectTest.php

示例10: findAll

 /**
  * {@inheritDoc}
  */
 public function findAll()
 {
     $this->source->clear();
     return $this->source->find();
 }
开发者ID:vardius,项目名称:crud-bundle,代码行数:8,代码来源:DataProvider.php

示例11: testSelectArrayWithColumnOrder

 public function testSelectArrayWithColumnOrder()
 {
     BookstoreDataPopulator::depopulate($this->con);
     BookstoreDataPopulator::populate($this->con);
     $c = new ModelCriteria('bookstore', 'Book');
     $c->join('Book.Author');
     $c->withColumn('LOWER(Book.Title)', 'LowercaseTitle');
     $c->withColumn('UPPER(Book.Title)', 'UppercaseTitle');
     $c->select(array('Book.ISBN', 'LowercaseTitle', 'Book.Title', 'UppercaseTitle'));
     $c->orderBy('Book.Title');
     $rows = $c->find($this->con);
     $expectedSQL = 'SELECT book.isbn AS "Book.ISBN", LOWER(book.title) AS LowercaseTitle, book.title AS "Book.Title", UPPER(book.title) AS UppercaseTitle FROM `book` INNER JOIN `author` ON (book.author_id=author.id) ORDER BY book.title ASC';
     $this->assertEquals($expectedSQL, $this->con->getLastExecutedQuery(), 'find() called after select(array) can cope with a column added with withColumn()');
     $expectedRows = array(array('Book.ISBN' => '0140422161', 'LowercaseTitle' => 'don juan', 'Book.Title' => 'Don Juan', 'UppercaseTitle' => 'DON JUAN'), array('Book.ISBN' => '043935806X', 'LowercaseTitle' => 'harry potter and the order of the phoenix', 'Book.Title' => 'Harry Potter and the Order of the Phoenix', 'UppercaseTitle' => 'HARRY POTTER AND THE ORDER OF THE PHOENIX'), array('Book.ISBN' => '0380977427', 'LowercaseTitle' => 'quicksilver', 'Book.Title' => 'Quicksilver', 'UppercaseTitle' => 'QUICKSILVER'), array('Book.ISBN' => '067972575X', 'LowercaseTitle' => 'the tin drum', 'Book.Title' => 'The Tin Drum', 'UppercaseTitle' => 'THE TIN DRUM'));
     $this->assertEquals(serialize($rows->getData()), serialize($expectedRows), 'find() called after select(array) can cope with a column added with withColumn()');
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:16,代码来源:ModelCriteriaSelectTest.php


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