當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ModelCriteria::where方法代碼示例

本文整理匯總了PHP中ModelCriteria::where方法的典型用法代碼示例。如果您正苦於以下問題:PHP ModelCriteria::where方法的具體用法?PHP ModelCriteria::where怎麽用?PHP ModelCriteria::where使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ModelCriteria的用法示例。


在下文中一共展示了ModelCriteria::where方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testExplainPlanFromObject

 public function testExplainPlanFromObject()
 {
     BookstoreDataPopulator::depopulate($this->con);
     BookstoreDataPopulator::populate($this->con);
     $db = Propel::getDb(BookPeer::DATABASE_NAME);
     $c = new ModelCriteria('bookstore', 'Book');
     $c->join('Book.Author');
     $c->where('Author.FirstName = ?', 'Neal');
     $c->select('Title');
     $explain = $c->explain($this->con);
     if ($db instanceof DBMySQL) {
         $this->assertEquals(sizeof($explain), 2, 'Explain plan return two lines');
         // explain can change sometime, test can't be strict
         $this->assertArrayHasKey('select_type', $explain[0], 'Line 1, select_type key exist');
         $this->assertArrayHasKey('table', $explain[0], 'Line 1, table key exist');
         $this->assertArrayHasKey('type', $explain[0], 'Line 1, type key exist');
         $this->assertArrayHasKey('possible_keys', $explain[0], 'Line 1, possible_keys key exist');
         $this->assertArrayHasKey('select_type', $explain[1], 'Line 2, select_type key exist');
         $this->assertArrayHasKey('table', $explain[1], 'Line 2, table key exist');
         $this->assertArrayHasKey('type', $explain[1], 'Line 2, type key exist');
         $this->assertArrayHasKey('possible_keys', $explain[1], 'Line 2, possible_keys key exist');
     } elseif ($db instanceof DBOracle) {
         $this->assertTrue(sizeof($explain) > 2, 'Explain plan return more than 2 lines');
     } else {
         $this->markTestSkipped('Cannot test explain plan on adapter ' . get_class($db));
     }
 }
開發者ID:kalaspuffar,項目名稱:php-orm-benchmark,代碼行數:27,代碼來源:ExplainPlanTest.php

示例2: testFindOneWithDistantClass

 public function testFindOneWithDistantClass()
 {
     BookstoreDataPopulator::populate();
     BookPeer::clearInstancePool();
     AuthorPeer::clearInstancePool();
     ReviewPeer::clearInstancePool();
     $c = new ModelCriteria('bookstore', 'Review');
     $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $c->where('Review.Recommended = ?', true);
     $c->join('Review.Book');
     $c->with('Book');
     $c->join('Book.Author');
     $c->with('Author');
     $review = $c->findOne();
     $this->assertEquals($review['ReviewedBy'], 'Washington Post', 'Main object is correctly hydrated');
     $book = $review['Book'];
     $this->assertEquals('Harry Potter and the Order of the Phoenix', $book['Title'], 'Related object is correctly hydrated');
     $author = $book['Author'];
     $this->assertEquals('J.K.', $author['FirstName'], 'Related object is correctly hydrated');
 }
開發者ID:keneanung,項目名稱:gw2spidy,代碼行數:20,代碼來源:PropelArrayFormatterWithTest.php

示例3: testFindOneWithDistantClass

 public function testFindOneWithDistantClass()
 {
     BookstoreDataPopulator::populate();
     BookPeer::clearInstancePool();
     AuthorPeer::clearInstancePool();
     ReviewPeer::clearInstancePool();
     Propel::enableInstancePooling();
     $c = new ModelCriteria('bookstore', 'Review');
     $c->where('Review.Recommended = ?', true);
     $c->join('Review.Book');
     $c->with('Book');
     $c->join('Book.Author');
     $c->with('Author');
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $review = $c->findOne($con);
     $count = $con->getQueryCount();
     $this->assertEquals($review->getReviewedBy(), 'Washington Post', 'Main object is correctly hydrated');
     $book = $review->getBook();
     $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:halfer,項目名稱:Meshing,代碼行數:24,代碼來源:PropelObjectFormatterWithTest.php

示例4: testUseQueryCustomClass

 public function testUseQueryCustomClass()
 {
     $c = new ModelCriteria('bookstore', 'Book', 'b');
     $c->thisIsMe = true;
     $c->where('b.Title = ?', 'foo');
     $c->setLimit(10);
     $c->leftJoin('b.Author a');
     $c2 = $c->useQuery('a', 'ModelCriteriaForUseQuery');
     $this->assertTrue($c2 instanceof ModelCriteriaForUseQuery, 'useQuery() returns a secondary Criteria with the custom class');
     $c2->withNoName();
     $c = $c2->endUse();
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $c->find($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 book.TITLE = 'foo' AND a.FIRST_NAME IS NOT NULL  AND a.LAST_NAME IS NOT NULL LIMIT 10";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'useQuery() and endUse() allow to merge a custom secondary criteria');
 }
開發者ID:ketheriel,項目名稱:ETVA,代碼行數:16,代碼來源:ModelCriteriaTest.php

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

示例6: testExistsWithNonExistentCondition

 public function testExistsWithNonExistentCondition()
 {
     $c = new ModelCriteria('bookstore', 'Book', 'b');
     $c->where('b.Title = ?', 'jenexistepas');
     $this->assertFalse($c->exists());
 }
開發者ID:ruian,項目名稱:Propel,代碼行數:6,代碼來源:ModelCriteriaTest.php

示例7: filterByKeyword

 protected function filterByKeyword(\ModelCriteria $query, $params)
 {
     if (!empty($params['q'])) {
         $columns = array();
         $peerClass = constant($this->query->getModelName() . '::PEER');
         $phpNames = call_user_func(array($peerClass, 'getFieldNames'));
         foreach ($this->columns as $name => $column) {
             if (!empty($column['phpName'])) {
                 if (in_array($column['phpName'], $phpNames)) {
                     $columns[] = $this->query->getModelName() . '.' . $column['phpName'];
                 }
             }
         }
         array_unshift($columns, '"|"');
         $query->where('CONCAT_WS(' . join(',', $columns) . ') LIKE ?', '%' . $params['q'] . '%');
     }
 }
開發者ID:bombayworks,項目名稱:currycms,代碼行數:17,代碼來源:ListView.php

示例8: 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::where方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。