Changeset 10119
- Timestamp:
- 07/04/08 15:11:30 (3 months ago)
- Files:
-
- plugins/sfPropelFinderPlugin/README (modified) (6 diffs)
- plugins/sfPropelFinderPlugin/lib/sfPropelFinder.php (modified) (2 diffs)
- plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderTest.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfPropelFinderPlugin/README
r10118 r10119 200 200 $comment->setArticle($article1); 201 201 $comment->save(); 202 202 203 // Add a join statement 203 204 // No need to tell the finder which columns to use for the join, just the related Class … … 207 208 where('Comment.Content', 'You rock!')-> 208 209 findOne(); 210 211 // As a matter of fact, join() is optional 212 // You can omit it if the join is simple and the finder can guess it 213 // That is, if you add conditions with explicit column names 214 $article = sfPropelFinder::from('Article')-> 215 where('Comment.Content', 'You rock!')-> 216 findOne(); 217 209 218 // You can chain joins if you want to make it more complex 210 219 $article2 = new Article(); … … 219 228 $comment->setAuthor($author1); 220 229 $comment->save(); 230 221 231 $article = sfPropelFinder::from('Article')-> 222 232 join('Comment')-> … … 224 234 where('Author.Name', 'John')-> 225 235 findOne(); 236 // In this example, Author.Name allows the finder to guess the last join 237 // So you can omit it 238 $article = sfPropelFinder::from('Article')-> 239 join('Comment')-> 240 where('Author.Name', 'John')-> 241 findOne(); 242 226 243 // You can also use the magic joinXXX() method 244 $article = sfPropelFinder::from('Article')-> 245 joinComment()-> 246 where('Author.Name', 'John')-> 247 findOne(); 227 248 }}} 228 249 … … 479 500 * Add support for `with()` in `findPk()` (and document the method) 480 501 * Add the ability to do left, right, inner joins, etc. 481 * Make `join()` useless if there is an explicit `where()` on the table afterwards482 502 * Change `with()` and `join()` to accept only one relation at a time, but with the ability to set the local and foreign parts of the relation. maybe replace the current multiple ability of these methods by `joins()` and `withs()` 483 503 * Handle complex queries with And and Or … … 490 510 === 2008-07-04 | Trunk === 491 511 512 * francois: Made `join()` useless if there is an explicit `where()` on the table afterwards 492 513 * francois: Added a `prove.php` test file to launch all tests at once in a test harness 493 514 * francois: Moved utility methods as static methods of a third-party class to take some weight off the main class plugins/sfPropelFinderPlugin/lib/sfPropelFinder.php
r10118 r10119 910 910 return $this; 911 911 } 912 912 913 protected function hasRelation($peerName) 914 { 915 return in_array($peerName, $this->relations); 916 } 917 913 918 public function getRelation($phpName) 914 919 { … … 1005 1010 $peerClass = $this->peerClass; 1006 1011 } 1012 if($peerClass != $this->peerClass && !$this->hasRelation($peerClass)) 1013 { 1014 $this->join($class); 1015 } 1007 1016 try 1008 1017 { plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderTest.php
r10112 r10119 65 65 ArticlePeer::doDeleteAll(); 66 66 67 $t = new lime_test(14 2, new lime_output_color());67 $t = new lime_test(146, new lime_output_color()); 68 68 69 69 $t->diag('find()'); … … 626 626 $nbArticles = sfPropelFinder::from('Article')->join('Category')->where('Category.Name', 'cat1')->count(); 627 627 $t->is($nbArticles, 2, 'join() allows to join to another table (many-to-one)'); 628 $nbArticles = sfPropelFinder::from('Article')->where('Category.Name', 'cat1')->count(); 629 $t->is($nbArticles, 2, 'join() can be omitted if column names are explicit (many-to-one)'); 628 630 $nbArticles = sfPropelFinder::from('Article')->join('Category')->where('Category.Name', 'cat2')->count(); 629 631 $t->is($nbArticles, 1, 'join() allows to join to another table (many-to-one)'); 632 $nbArticles = sfPropelFinder::from('Article')->join('Category')->where('Category.Name', 'cat2')->count(); 633 $t->is($nbArticles, 1, 'join() can be omitted if column names are explicit (many-to-one)'); 630 634 $article = sfPropelFinder::from('Article')->join('Category')->where('Category.Name', 'cat2')->findOne(); 631 635 $t->is($article->getTitle(), 'ccccc', 'join() allows to join to another table (many-to-one)'); … … 646 650 $nbArticles = sfPropelFinder::from('Article')->join('Comment')->where('Comment.Content', 'foo')->count(); 647 651 $t->is($nbArticles, 1, 'join() allows to join to another table (one-to-many)'); 652 $nbArticles = sfPropelFinder::from('Article')->where('Comment.Content', 'foo')->count(); 653 $t->is($nbArticles, 1, 'join() can be omitted if column names are explicit (one-to-many)'); 648 654 $article = sfPropelFinder::from('Article')->join('Comment')->where('Comment.Content', 'foo')->findOne(); 649 655 $t->is($article->getTitle(), 'bbbbb', 'join() allows to join to another table (one-to-many)'); … … 666 672 $article = sfPropelFinder::from('Article')->join('Comment')->join('Author')->where('Author.Name', 'John')->findOne(); 667 673 $t->is($article->getTitle(), 'aaaaa', 'you can chain several join() statements'); 674 $article = sfPropelFinder::from('Article')->join('Comment')->where('Author.Name', 'John')->findOne(); 675 $t->is($article->getTitle(), 'aaaaa', 'join() can be omitted if column names are explicit'); 668 676 $article = sfPropelFinder::from('Article')->joinComment()->joinAuthor()->where('Author.Name', 'John')->findOne(); 669 677 $t->is($article->getTitle(), 'aaaaa', 'joinXXX() does a join according to the XXX column name');