Changeset 10085
- Timestamp:
- 07/03/08 14:05:07 (2 months ago)
- Files:
-
- plugins/sfPropelFinderPlugin/README (modified) (2 diffs)
- plugins/sfPropelFinderPlugin/lib/sfPropelFinder.php (modified) (3 diffs)
- plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderTest.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfPropelFinderPlugin/README
r10074 r10085 15 15 $c->add(ArticlePeer::IS_PUBLISHED, true); 16 16 $c->addAscendingOrderByColumn(ArticlePeer::CREATED_AT); 17 $articles = ArticlePeer::doSelect ($c);17 $articles = ArticlePeer::doSelectJoinCategory($c); 18 18 19 19 // with sfPropelFinder 20 $articles = sfPropelFinder::from('Article')->whereTitle('like', '%world')->whereIsPublished(true)->orderByCreatedAt()->find(); 21 }}} 22 23 `sfPropelFinder` uses the same fluid interface as the `sfFinder`, so you won't be lost. 20 $articles = sfPropelFinder::from('Article')-> 21 where('Title', 'like', '%world')-> 22 where('IsPublished', true)-> 23 order('ByCreatedAt')-> 24 with('Category')-> 25 find(); 26 }}} 27 28 `sfPropelFinder` uses the same fluid interface as the `sfFinder`, so you won't be lost. It is compatible with symfony 1.0 and 1.1, and with Propel 1.2 and 1.3. 24 29 25 30 You can also implement your own business logic to encapsulate complex queries, so that your queries look like real language: … … 476 481 == Changelog == 477 482 478 === 2008-07-02 | Trunk === 479 483 === 2008-07-03 | Trunk === 484 485 * francois: Added Propel 1.3 compatibility 480 486 * francois: Added `sfPropelFinder::set()` method (based on a patch by jug) 481 487 * francois: Added `sfPropelFinder::withI18n()` method plugins/sfPropelFinderPlugin/lib/sfPropelFinder.php
r10074 r10085 430 430 { 431 431 $c = $this->prepareCompositeCriteria($criteria); 432 $resultSet = call_user_func(array($this->getPeerClass(), 'doSelectRS'), $c, $con); 432 if(method_exists($this->getPeerClass(), 'doSelectRS')) 433 { 434 $resultSet = call_user_func(array($this->getPeerClass(), 'doSelectRS'), $c, $con); 435 $propelVersion = '1.2'; 436 $nextFunction = 'next'; 437 $nextParam = null; 438 } 439 else 440 { 441 $resultSet = call_user_func(array($this->getPeerClass(), 'doSelectStmt'), $c, $con); 442 $propelVersion = '1.3'; 443 $nextFunction = 'fetch'; 444 $nextParam = PDO::FETCH_NUM; 445 } 433 446 434 447 // Hydrate the objects based on the resultset 435 448 $omClass = call_user_func(array($this->getPeerClass(), 'getOMClass')); 436 $cls = Propel::import($omClass);449 $cls = substr('.'.$omClass, strrpos('.'.$omClass, '.') + 1); 437 450 $objects = array(); 438 451 $withObjs = array(); 439 while ($r esultSet->next())452 while ($row = $resultSet->$nextFunction($nextParam)) 440 453 { 441 454 // First come the columns of the main class 442 455 $obj = new $cls(); 443 $startCol = $obj->hydrate($resultSet, 1); 456 if($propelVersion == '1.2') 457 { 458 $startCol = $obj->hydrate($resultSet, 1); 459 } 460 else 461 { 462 $startCol = $obj->hydrate($row, 0); 463 } 444 464 if($this->culture) 445 465 { … … 451 471 { 452 472 $withObj = new $className(); 453 $startCol = $withObj->hydrate($resultSet, $startCol); 473 if($propelVersion == '1.2') 474 { 475 $startCol = $withObj->hydrate($resultSet, $startCol); 476 } 477 else 478 { 479 $startCol = $withObj->hydrate($row, $startCol); 480 } 454 481 455 482 // initialize our object directory … … 485 512 // Using the third parameter of withColumn() as a type. defaults to $rs->get() (= $rs->getString()) 486 513 $typedGetter = 'get'.ucfirst($column['type']); 487 $obj->$asName = $resultSet->$typedGetter($startCol); 514 if($propelVersion == '1.2') 515 { 516 $obj->$asName = $resultSet->$typedGetter($startCol); 517 } 518 else 519 { 520 $obj->$asName = $row[$startCol]; 521 } 488 522 $startCol++; 489 523 } plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderTest.php
r10074 r10085 65 65 ArticlePeer::doDeleteAll(); 66 66 67 $t = new lime_test(14 2, new lime_output_color());67 $t = new lime_test(141, new lime_output_color()); 68 68 69 69 $t->diag('find()'); … … 830 830 $article = sfPropelFinder::from('Article')-> 831 831 join('Comment')-> 832 groupBy('Article_Id')-> 832 833 withColumn('COUNT(comment.ID)', 'NbComments')-> 833 834 findOne(); … … 836 837 $finder = sfPropelFinder::from('Article')-> 837 838 join('Comment')-> 839 groupBy('Article_Id')-> 838 840 withColumn('COUNT(comment.ID)', 'NbComments')-> 839 841 orderBy('NbComments'); 840 842 $article = $finder->findOne(); 841 $t->is($finder->getLatestQuery(), 'SELECT article.ID, article.VERSION, article.TITLE, article.CATEGORY_ID, COUNT(comment.ID) AS NbComments FROM article, comment WHERE article.ID=comment.ARTICLE_ID ORDER BY NbComments ASC LIMIT 1', 'Columns added with withColumn() can be used for sorting'); 842 843 $finder = sfPropelFinder::from('Article')-> 844 join('Comment')-> 845 withColumn('COUNT(comment.ID)', 'NbComments')-> 846 addGroupByColumn('NbComments'); 847 $article = $finder->findOne(); 848 $t->is($finder->getLatestQuery(), 'SELECT article.ID, article.VERSION, article.TITLE, article.CATEGORY_ID, COUNT(comment.ID) AS NbComments FROM article, comment WHERE article.ID=comment.ARTICLE_ID GROUP BY NbComments LIMIT 1', 'Columns added with withColumn() can be used for grouping'); 843 $t->is($finder->getLatestQuery(), 'SELECT article.ID, article.VERSION, article.TITLE, article.CATEGORY_ID, COUNT(comment.ID) AS NbComments FROM article, comment WHERE article.ID=comment.ARTICLE_ID GROUP BY article.ID ORDER BY NbComments ASC LIMIT 1', 'Columns added with withColumn() can be used for sorting'); 849 844 850 845 $t->diag('set()');