当前位置: 首页>>代码示例>>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;未经允许,请勿转载。