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


PHP ModelCriteria::findOne方法代码示例

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


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

示例1: findBy

 /**
  * {@inheritDoc}
  */
 public function findBy(array $criteria)
 {
     $this->source->clear();
     foreach ($criteria as $field => $value) {
         $method = 'filterBy' . ucfirst($field);
         $this->source->{$method}($value);
     }
     return $this->source->findOne();
 }
开发者ID:vardius,项目名称:crud-bundle,代码行数:12,代码来源:DataProvider.php

示例2: testFindOneWithClassAndColumn

 public function testFindOneWithClassAndColumn()
 {
     BookstoreDataPopulator::populate();
     BookPeer::clearInstancePool();
     AuthorPeer::clearInstancePool();
     ReviewPeer::clearInstancePool();
     $c = new ModelCriteria('bookstore', 'Book');
     $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $c->filterByTitle('The Tin Drum');
     $c->join('Book.Author');
     $c->withColumn('Author.FirstName', 'AuthorName');
     $c->withColumn('Author.LastName', 'AuthorName2');
     $c->with('Author');
     $con = Propel::getConnection(BookPeer::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'], 'PropelArrayFormatter correctly hydrates withclass and columns');
     $this->assertEquals('Gunter', $book['AuthorName'], 'PropelArrayFormatter adds withColumns as columns');
     $this->assertEquals('Grass', $book['AuthorName2'], 'PropelArrayFormatter correctly hydrates all as columns');
 }
开发者ID:keneanung,项目名称:gw2spidy,代码行数:21,代码来源:PropelArrayFormatterWithTest.php

示例3: testFindOneWithClassAndColumn

 public function testFindOneWithClassAndColumn()
 {
     BookstoreDataPopulator::populate();
     BookPeer::clearInstancePool();
     AuthorPeer::clearInstancePool();
     ReviewPeer::clearInstancePool();
     $c = new ModelCriteria('bookstore', 'Book');
     $c->filterByTitle('The Tin Drum');
     $c->join('Book.Author');
     $c->withColumn('Author.FirstName', 'AuthorName');
     $c->withColumn('Author.LastName', 'AuthorName2');
     $c->with('Author');
     $con = Propel::getConnection(BookPeer::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, '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:halfer,项目名称:Meshing,代码行数:21,代码来源:PropelObjectFormatterWithTest.php

示例4: testFindOneWithDistantClassRenamedRelation

 public function testFindOneWithDistantClassRenamedRelation()
 {
     BookstoreDataPopulator::populate();
     BookPeer::clearInstancePool();
     AuthorPeer::clearInstancePool();
     ReviewPeer::clearInstancePool();
     Propel::enableInstancePooling();
     $c = new ModelCriteria('bookstore', 'BookSummary');
     $c->joinWith('BookSummary.SummarizedBook');
     $c->joinWith('SummarizedBook.Author');
     $c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
     $con = Propel::getConnection(BookPeer::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');
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:22,代码来源:PropelOnDemandFormatterWithTest.php

示例5: testMagicJoin

 public function testMagicJoin()
 {
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $c = new ModelCriteria('bookstore', 'Book', 'b');
     $c->leftJoin('b.Author a');
     $c->where('a.FirstName = ?', 'Leo');
     $books = $c->findOne($con);
     $expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` LEFT JOIN `author` `a` ON (book.AUTHOR_ID=a.ID) WHERE a.FIRST_NAME = 'Leo' LIMIT 1";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'leftJoin($x) is turned into join($x, Criteria::LEFT_JOIN)');
     $books = BookQuery::create()->leftJoinAuthor('a')->where('a.FirstName = ?', 'Leo')->findOne($con);
     $expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` LEFT JOIN `author` `a` ON (book.AUTHOR_ID=a.ID) WHERE a.FIRST_NAME = 'Leo' LIMIT 1";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'leftJoinX() is turned into join($x, Criteria::LEFT_JOIN)');
     $c = new ModelCriteria('bookstore', 'Book', 'b');
     $c->innerJoin('b.Author a');
     $c->where('a.FirstName = ?', 'Leo');
     $books = $c->findOne($con);
     $expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` INNER JOIN `author` `a` ON (book.AUTHOR_ID=a.ID) WHERE a.FIRST_NAME = 'Leo' LIMIT 1";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'innerJoin($x) is turned into join($x, Criteria::INNER_JOIN)');
     $books = BookQuery::create()->innerJoinAuthor('a')->where('a.FirstName = ?', 'Leo')->findOne($con);
     $expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` INNER JOIN `author` `a` ON (book.AUTHOR_ID=a.ID) WHERE a.FIRST_NAME = 'Leo' LIMIT 1";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'innerJoinX() is turned into join($x, Criteria::INNER_JOIN)');
     $c = new ModelCriteria('bookstore', 'Book', 'b');
     $c->rightJoin('b.Author a');
     $c->where('a.FirstName = ?', 'Leo');
     $books = $c->findOne($con);
     $expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` RIGHT JOIN `author` `a` ON (book.AUTHOR_ID=a.ID) WHERE a.FIRST_NAME = 'Leo' LIMIT 1";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'rightJoin($x) is turned into join($x, Criteria::RIGHT_JOIN)');
     $books = BookQuery::create()->rightJoinAuthor('a')->where('a.FirstName = ?', 'Leo')->findOne($con);
     $expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` RIGHT JOIN `author` `a` ON (book.AUTHOR_ID=a.ID) WHERE a.FIRST_NAME = 'Leo' LIMIT 1";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'rightJoinX() is turned into join($x, Criteria::RIGHT_JOIN)');
     $books = BookQuery::create()->leftJoinAuthor()->where('Author.FirstName = ?', 'Leo')->findOne($con);
     $expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` LEFT JOIN `author` ON (book.AUTHOR_ID=author.ID) WHERE author.FIRST_NAME = 'Leo' LIMIT 1";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'leftJoinX() is turned into join($x, Criteria::LEFT_JOIN)');
 }
开发者ID:ketheriel,项目名称:ETVA,代码行数:34,代码来源:ModelCriteriaTest.php

示例6: 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', 'Book');
     $books = $c->find();
     foreach ($books as $book) {
         $book->save();
     }
     BookPeer::clearInstancePool();
     // retrieve the test data
     $c = new ModelCriteria('bookstore', 'BookListRel');
     $bookListRelTest = $c->findOne();
     $pk = $bookListRelTest->getPrimaryKey();
     $q = new BookListRelQuery();
     $q->filterByPrimaryKey($pk);
     $q1 = BookListRelQuery::create()->add(BookListRelPeer::BOOK_ID, $pk[0], Criteria::EQUAL)->add(BookListRelPeer::BOOK_CLUB_LIST_ID, $pk[1], Criteria::EQUAL);
     $this->assertEquals($q1, $q, 'filterByPrimaryKey() translates to a Criteria::EQUAL in the PK columns');
 }
开发者ID:shelsonjava,项目名称:datawrapper,代码行数:20,代码来源:QueryBuilderTest.php

示例7: testMagicFindByObject

 public function testMagicFindByObject()
 {
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $c = new ModelCriteria('bookstore', 'Author');
     $testAuthor = $c->findOne();
     $q = BookQuery::create()->findByAuthor($testAuthor);
     $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', '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)');
 }
开发者ID:nevalla,项目名称:Propel,代码行数:14,代码来源:ModelCriteriaTest.php

示例8: testSelectArrayJoin

 public function testSelectArrayJoin()
 {
     BookstoreDataPopulator::depopulate($this->con);
     BookstoreDataPopulator::populate($this->con);
     $c = new ModelCriteria('bookstore', 'Book');
     $c->join('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 = "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', 'Book');
     $c->join('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', 'Book');
     $c->join('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 = "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', 'Book');
     $c->join('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');
 }
开发者ID:rubensayshi,项目名称:propelsandbox,代码行数:33,代码来源:ModelCriteriaSelectTest.php

示例9: testQuotingAliases

 public function testQuotingAliases()
 {
     $c = new ModelCriteria('bookstore', 'Book');
     $c->withColumn('book.title', 'Book Title (*.)');
     $c->select('Book Title (*.)');
     $c->where('Book.Isbn = ?', '0380977427');
     $title = $c->findOne();
     $expectedSQL = "SELECT book.title AS `Book Title (*.)` FROM `book` WHERE book.isbn = '0380977427' LIMIT 1";
     $this->assertEquals($expectedSQL, $this->con->getLastExecutedQuery());
     $this->assertEquals('Quicksilver', $title);
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:11,代码来源:ModelCriteriaSelectTest.php


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