本文整理汇总了PHP中Propel\Runtime\ActiveQuery\ModelCriteria::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelCriteria::findOne方法的具体用法?PHP ModelCriteria::findOne怎么用?PHP ModelCriteria::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Runtime\ActiveQuery\ModelCriteria
的用法示例。
在下文中一共展示了ModelCriteria::findOne方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: genericUpdateDelegatePosition
/**
* @param ModelCriteria $query
* @param UpdatePositionEvent $event
* @param EventDispatcherInterface|null $dispatcher
*
* @since 2.3
*/
protected function genericUpdateDelegatePosition(ModelCriteria $query, UpdatePositionEvent $event, EventDispatcherInterface $dispatcher = null)
{
if (null !== ($object = $query->findOne())) {
if (!isset(class_uses($object)['Thelia\\Model\\Tools\\PositionManagementTrait'])) {
throw new \InvalidArgumentException("Your model does not implement the PositionManagementTrait trait");
}
//$object->setDispatcher($dispatcher !== null ? $dispatcher : $event->getDispatcher());
$mode = $event->getMode();
if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE) {
$object->changeAbsolutePosition($event->getPosition());
} elseif ($mode == UpdatePositionEvent::POSITION_UP) {
$object->movePositionUp();
} elseif ($mode == UpdatePositionEvent::POSITION_DOWN) {
$object->movePositionDown();
}
}
}
示例2: testFindOneWithDistantClassRenamedRelation
public function testFindOneWithDistantClassRenamedRelation()
{
BookstoreDataPopulator::populate();
BookTableMap::clearInstancePool();
AuthorTableMap::clearInstancePool();
ReviewTableMap::clearInstancePool();
Propel::enableInstancePooling();
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\BookSummary');
$c->joinWith('Propel\\Tests\\Bookstore\\BookSummary.SummarizedBook');
$c->joinWith('SummarizedBook.Author');
$c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
$summary = $c->findOne($con);
$count = $con->getQueryCount();
$this->assertEquals('Harry Potter does some amazing magic!', $summary->getSummary(), 'Main object is correctly hydrated');
$book = $summary->getSummarizedBook();
$this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query');
$this->assertEquals('Harry Potter and the Order of the Phoenix', $book->getTitle(), 'Related object is correctly hydrated');
$author = $book->getAuthor();
$this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query');
$this->assertEquals('J.K.', $author->getFirstName(), 'Related object is correctly hydrated');
}
示例3: testRequirePkReturnsModel
public function testRequirePkReturnsModel()
{
// retrieve the test data
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$testBook = $c->findOne();
$book = BookQuery::create()->requirePk($testBook->getId());
$this->assertInstanceOf(BookTableMap::OM_CLASS, $book);
}
示例4: testFilterByPrimaryKeyCompositeKey
public function testFilterByPrimaryKeyCompositeKey()
{
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();
// retrieve the test data
$c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\BookListRel');
$bookListRelTest = $c->findOne();
$pk = $bookListRelTest->getPrimaryKey();
$q = new BookListRelQuery();
$q->filterByPrimaryKey($pk);
$q1 = BookListRelQuery::create()->add(BookListRelTableMap::BOOK_ID, $pk[0], Criteria::EQUAL)->add(BookListRelTableMap::BOOK_CLUB_LIST_ID, $pk[1], Criteria::EQUAL);
$this->assertEquals($q1, $q, 'filterByPrimaryKey() translates to a Criteria::EQUAL in the PK columns');
}
示例5: testFindOneWithClassAndColumn
public function testFindOneWithClassAndColumn()
{
BookstoreDataPopulator::populate();
BookTableMap::clearInstancePool();
AuthorTableMap::clearInstancePool();
ReviewTableMap::clearInstancePool();
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$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');
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
$book = $c->findOne($con);
$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: testMagicFindByObject
public function testMagicFindByObject()
{
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Author');
$testAuthor = $c->findOne();
$q = BookQuery::create()->findByAuthor($testAuthor);
$expectedSQL = $this->getSql("SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM book WHERE book.author_id=" . $testAuthor->getId());
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'findByXXX($value) is turned into findBy(XXX, $value)');
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Author');
$testAuthor = $c->findOne();
$q = BookQuery::create()->findByAuthorAndISBN($testAuthor, 1234);
$expectedSQL = $this->getSql("SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM book WHERE book.author_id=" . $testAuthor->getId() . " AND book.isbn=1234");
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'findByXXXAndYYY($value) is turned into findBy(array(XXX, YYY), $value)');
}
示例7: testSelectArrayJoin
public function testSelectArrayJoin()
{
BookstoreDataPopulator::depopulate($this->con);
BookstoreDataPopulator::populate($this->con);
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$c->join('Propel\\Tests\\Bookstore\\Book.Author');
$c->where('Author.FirstName = ?', 'Neal');
$c->select(array('Title', 'ISBN'));
$titles = $c->find($this->con);
$this->assertEquals($titles->count(), 1, 'find() called after select(array) allows for join() statements');
$expectedSQL = $this->getSql("SELECT book.TITLE AS \"Title\", book.ISBN AS \"ISBN\" FROM `book` INNER JOIN `author` ON (book.AUTHOR_ID=author.ID) WHERE author.FIRST_NAME = 'Neal'");
$this->assertEquals($expectedSQL, $this->con->getLastExecutedQuery(), 'find() called after select(array) allows for join() statements');
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$c->join('Propel\\Tests\\Bookstore\\Book.Author');
$c->where('Author.FirstName = ?', 'Neal');
$c->select(array('Author.FirstName', 'Author.LastName'));
$titles = $c->find($this->con);
$this->assertEquals(array_values($titles->shift()), array('Neal', 'Stephenson'), 'find() called after select(array) will return values from the joined table using complete column names');
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$c->join('Propel\\Tests\\Bookstore\\Book.Author');
$c->where('Author.FirstName = ?', 'Neal');
$c->select(array('Title', 'ISBN'));
$title = $c->findOne($this->con);
$this->assertEquals(count($title), 2, 'findOne() called after select(array) allows for join() statements');
$expectedSQL = $this->getSql("SELECT book.TITLE AS \"Title\", book.ISBN AS \"ISBN\" FROM `book` INNER JOIN `author` ON (book.AUTHOR_ID=author.ID) WHERE author.FIRST_NAME = 'Neal' LIMIT 1");
$this->assertEquals($expectedSQL, $this->con->getLastExecutedQuery(), 'findOne() called after select(array) allows for join() statements');
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$c->join('Propel\\Tests\\Bookstore\\Book.Author');
$c->where('Author.FirstName = ?', 'Neal');
$c->select(array('Author.FirstName', 'Author.LastName'));
$title = $c->findOne($this->con);
$this->assertEquals(array_values($title), array('Neal', 'Stephenson'), 'findOne() called after select(array) will return values from the joined table using complete column names');
}
示例8: testFindOneWithClassAndColumn
public function testFindOneWithClassAndColumn()
{
BookstoreDataPopulator::populate();
BookTableMap::clearInstancePool();
AuthorTableMap::clearInstancePool();
ReviewTableMap::clearInstancePool();
$c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
$c->setFormatter(ModelCriteria::FORMAT_ARRAY);
$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');
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
$book = $c->findOne($con);
$this->assertEquals(array('Id', 'Title', 'ISBN', 'Price', 'PublisherId', 'AuthorId', 'Author', 'AuthorName', 'AuthorName2'), array_keys($book), 'withColumn() do not change the resulting model class');
$this->assertEquals('The Tin Drum', $book['Title']);
$this->assertEquals('Gunter', $book['Author']['FirstName'], 'ArrayFormatter correctly hydrates withclass and columns');
$this->assertEquals('Gunter', $book['AuthorName'], 'ArrayFormatter adds withColumns as columns');
$this->assertEquals('Grass', $book['AuthorName2'], 'ArrayFormatter correctly hydrates all as columns');
}
示例9: testMagicFindByObject
public function testMagicFindByObject()
{
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Author');
$testAuthor = $c->findOne();
$q = BookQuery::create()->findByAuthor($testAuthor);
if (in_array($this->getDriver(), array('mysql'))) {
$expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` WHERE book.AUTHOR_ID=" . $testAuthor->getId();
} else {
$expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM book WHERE book.AUTHOR_ID=" . $testAuthor->getId();
}
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'findByXXX($value) is turned into findBy(XXX, $value)');
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Author');
$testAuthor = $c->findOne();
$q = BookQuery::create()->findByAuthorAndISBN($testAuthor, 1234);
$expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` WHERE book.AUTHOR_ID=" . $testAuthor->getId() . " AND book.ISBN=1234";
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'findByXXXAndYYY($value) is turned into findBy(array(XXX, YYY), $value)');
}