本文整理汇总了PHP中Propel\Runtime\ActiveQuery\ModelCriteria::find方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelCriteria::find方法的具体用法?PHP ModelCriteria::find怎么用?PHP ModelCriteria::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Runtime\ActiveQuery\ModelCriteria
的用法示例。
在下文中一共展示了ModelCriteria::find方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadChunk
/**
* @return void
*/
protected function loadChunk()
{
$this->query->setOffset($this->offset);
$this->query->setLimit($this->chunkSize);
$this->currentDataSet = $this->query->find();
$this->offset += $this->chunkSize;
}
示例2: loadChoiceList
/**
* {@inheritdoc}
*/
public function loadChoiceList($value = null)
{
if ($this->choiceList) {
return $this->choiceList;
}
$models = iterator_to_array($this->query->find());
$this->choiceList = $this->factory->createListFromChoices($models, $value);
return $this->choiceList;
}
示例3: loadModelCriteria
/**
* @param ModelCriteria $criteria
* @return $this|null
*
* Loads a model criteria.
* Warning: This doesn't goodly support multi table queries.
* If you need to use more than one table, use a PDO instance and
* use the fetchArray() method, or select every columns you need
*/
public function loadModelCriteria(ModelCriteria $criteria)
{
$propelData = $criteria->find();
if (empty($propelData)) {
return null;
}
$asColumns = $propelData->getFormatter()->getAsColumns();
/**
* Format it correctly
* After this pass, we MUST have a 2D array.
* The first may be keyed with integers.
*/
$formattedResult = $propelData->toArray(null, false, TableMap::TYPE_COLNAME);
if (count($asColumns) > 1) {
/**
* Request with multiple select
* Apply propel aliases
*/
$formattedResult = $this->applyAliases($formattedResult, $asColumns);
} elseif (count($asColumns) === 1) {
/**
* Request with one select
*/
$key = str_replace("\"", "", array_keys($asColumns)[0]);
$formattedResult = [[$key => $formattedResult[0]]];
}
$data = $this->applyAliases($formattedResult, $this->aliases);
/**
* Then store it
*/
$this->data = $data;
return $this;
}
示例4: testPreAndPostDelete
public function testPreAndPostDelete()
{
$c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
$books = $c->find();
$count = count($books);
$book = $books->shift();
$this->con->lastAffectedRows = 0;
$c = new ModelCriteriaWithPreAndPostDeleteHook('bookstore', '\\Propel\\Tests\\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', '\\Propel\\Tests\\Bookstore\\Book');
$nbBooks = $c->deleteAll($this->con);
$this->assertEquals(12, $this->con->lastAffectedRows, 'postDelete() is called after deleteAll() even if preDelete() returns not null');
}
示例5: testFindOneWithClassAndColumn
public function testFindOneWithClassAndColumn()
{
BookstoreDataPopulator::populate();
BookTableMap::clearInstancePool();
AuthorTableMap::clearInstancePool();
ReviewTableMap::clearInstancePool();
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
$c->filterByTitle('The Tin Drum');
$c->join('Propel\\Tests\\Bookstore\\Book.Author');
$c->withColumn('Author.FirstName', 'AuthorName');
$c->withColumn('Author.LastName', 'AuthorName2');
$c->with('Author');
$c->limit(1);
$con = Propel::getServiceContainer()->getConnection(BookTableMap::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, 'ObjectFormatter correctly hydrates with class');
$this->assertEquals('Gunter', $book->getAuthor()->getFirstName(), 'ObjectFormatter correctly hydrates with class');
$this->assertEquals('Gunter', $book->getVirtualColumn('AuthorName'), 'ObjectFormatter adds withColumns as virtual columns');
$this->assertEquals('Grass', $book->getVirtualColumn('AuthorName2'), 'ObjectFormatter correctly hydrates all virtual columns');
}
示例6: 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');
}
示例7: 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', '\\Propel\\Tests\\Bookstore\\Book');
$books = $c->find();
foreach ($books as $book) {
$book->save();
}
BookTableMap::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');
}
示例8: testFindOneWithColumnAndAlias
public function testFindOneWithColumnAndAlias()
{
BookstoreDataPopulator::populate();
BookTableMap::clearInstancePool();
AuthorTableMap::clearInstancePool();
ReviewTableMap::clearInstancePool();
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$c->filterByTitle('Harry Potter and the Order of the Phoenix');
$c->joinWith('Propel\\Tests\\Bookstore\\Book.BookSummary');
$c->joinWith('Propel\\Tests\\Bookstore\\Book.Review');
$c->join('Propel\\Tests\\Bookstore\\Book.Author');
$c->withColumn('Author.FirstName', 'AuthorName');
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
$book = $c->find($con)->get(0);
$count = $con->getQueryCount();
$reviews = $book->getReviews();
//Washington Post
$this->assertTrue($book instanceof Book, 'withColumn() do not change the resulting model class');
$this->assertEquals(2, count($reviews), 'Related objects are correctly hydrated');
$this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query ');
$this->assertEquals('J.K.', $book->getVirtualColumn('AuthorName'), 'ObjectFormatter adds withColumns as virtual columns');
}
示例9: searchWithOffset
/**
* @param ModelCriteria $search
*
* @return ObjectCollection
*/
protected function searchWithOffset(ModelCriteria $search)
{
$limit = intval($this->getArgValue('limit'));
if ($limit >= 0) {
$search->limit($limit);
}
$search->offset(intval($this->getArgValue('offset')));
return $search->find();
}
示例10: testFormatterWithSelect
public function testFormatterWithSelect()
{
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$c->keepQuery(false);
// just for this test's purpose
$c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
$c->select(array('Id', 'Title'));
$rows = $c->find($this->con);
$this->assertTrue($c->getFormatter() instanceof \Propel\Runtime\Formatter\OnDemandFormatter, 'The formatter is preserved');
}
示例11: testFindWithLeftJoinWithManyToOneAndNullObject
public function testFindWithLeftJoinWithManyToOneAndNullObject()
{
if (!$this->runningOnSQLite()) {
$this->markTestSkipped('This test is designed for SQLite as it saves an empty object.');
}
BookTableMap::clearInstancePool();
AuthorTableMap::clearInstancePool();
ReviewTableMap::clearInstancePool();
$review = new Review();
$review->setReviewedBy("Peter");
$review->setRecommended(true);
$review->save($this->con);
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Review');
$c->setFormatter(ModelCriteria::FORMAT_ARRAY);
$c->leftJoinWith('Propel\\Tests\\Bookstore\\Review.Book');
$c->leftJoinWith('Book.Author');
// should not raise a notice
$reviews = $c->find($this->con);
$this->assertTrue(true);
}
示例12: testFindOneWithOneToManyThenManyToOneUsingAlias
public function testFindOneWithOneToManyThenManyToOneUsingAlias()
{
BookstoreDataPopulator::populate();
BookTableMap::clearInstancePool();
AuthorTableMap::clearInstancePool();
ReviewTableMap::clearInstancePool();
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Author');
$c->add(AuthorTableMap::LAST_NAME, 'Rowling');
$c->leftJoinWith('Propel\\Tests\\Bookstore\\Author.Book b');
$c->leftJoinWith('b.Review r');
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
$authors = $c->find($con);
$this->assertEquals(1, count($authors), 'with() does not duplicate the main object');
$rowling = $authors[0];
$count = $con->getQueryCount();
$this->assertEquals($rowling->getFirstName(), 'J.K.', 'Main object is correctly hydrated');
$books = $rowling->getBooks();
$this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query ');
$this->assertEquals(1, count($books), 'Related objects are correctly hydrated');
$book = $books[0];
$this->assertEquals($book->getTitle(), 'Harry Potter and the Order of the Phoenix', 'Related object is correctly hydrated');
$reviews = $book->getReviews();
$this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query ');
$this->assertEquals(2, count($reviews), 'Related objects are correctly hydrated');
}
示例13: testFindWithLeftJoinWithManyToOneAndNullObject
public function testFindWithLeftJoinWithManyToOneAndNullObject()
{
if ('sqlite' !== $this->con->getAttribute(\PDO::ATTR_DRIVER_NAME)) {
$this->markTestSkipped('This test is designed for SQLite as it saves an empty object.');
}
BookTableMap::clearInstancePool();
AuthorTableMap::clearInstancePool();
ReviewTableMap::clearInstancePool();
$review = new Review();
$review->save($this->con);
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Review');
$c->setFormatter(ModelCriteria::FORMAT_ARRAY);
$c->leftJoinWith('Propel\\Tests\\Bookstore\\Review.Book');
$c->leftJoinWith('Book.Author');
// should not raise a notice
$reviews = $c->find($this->con);
$this->assertTrue(true);
}