Development

Changeset 10119

You must first sign up to be able to contribute.

Changeset 10119

Show
Ignore:
Timestamp:
07/04/08 15:11:30 (3 months ago)
Author:
francois
Message:

sfPropelFinderPlugin Made join() useless if there is an explicit where() on the table afterwards

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelFinderPlugin/README

    r10118 r10119  
    200200$comment->setArticle($article1); 
    201201$comment->save(); 
     202 
    202203// Add a join statement 
    203204// No need to tell the finder which columns to use for the join, just the related Class 
     
    207208  where('Comment.Content', 'You rock!')-> 
    208209  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 
    209218// You can chain joins if you want to make it more complex 
    210219$article2 = new Article(); 
     
    219228$comment->setAuthor($author1); 
    220229$comment->save(); 
     230 
    221231$article = sfPropelFinder::from('Article')-> 
    222232  join('Comment')-> 
     
    224234  where('Author.Name', 'John')-> 
    225235  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 
    226243// You can also use the magic joinXXX() method 
     244$article = sfPropelFinder::from('Article')-> 
     245  joinComment()-> 
     246  where('Author.Name', 'John')-> 
     247  findOne(); 
    227248}}} 
    228249 
     
    479500 * Add support for `with()` in `findPk()` (and document the method) 
    480501 * Add the ability to do left, right, inner joins, etc. 
    481  * Make `join()` useless if there is an explicit `where()` on the table afterwards 
    482502 * 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()` 
    483503 * Handle complex queries with And and Or 
     
    490510=== 2008-07-04 | Trunk === 
    491511 
     512 * francois: Made `join()` useless if there is an explicit `where()` on the table afterwards 
    492513 * francois: Added a `prove.php` test file to launch all tests at once in a test harness 
    493514 * 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  
    910910    return $this; 
    911911  } 
    912  
     912   
     913  protected function hasRelation($peerName) 
     914  { 
     915    return in_array($peerName, $this->relations); 
     916  } 
     917   
    913918  public function getRelation($phpName) 
    914919  { 
     
    10051010      $peerClass = $this->peerClass; 
    10061011    } 
     1012    if($peerClass != $this->peerClass && !$this->hasRelation($peerClass)) 
     1013    { 
     1014      $this->join($class); 
     1015    } 
    10071016    try 
    10081017    { 
  • plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderTest.php

    r10112 r10119  
    6565ArticlePeer::doDeleteAll(); 
    6666 
    67 $t = new lime_test(142, new lime_output_color()); 
     67$t = new lime_test(146, new lime_output_color()); 
    6868 
    6969$t->diag('find()'); 
     
    626626$nbArticles = sfPropelFinder::from('Article')->join('Category')->where('Category.Name', 'cat1')->count(); 
    627627$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)'); 
    628630$nbArticles = sfPropelFinder::from('Article')->join('Category')->where('Category.Name', 'cat2')->count(); 
    629631$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)'); 
    630634$article = sfPropelFinder::from('Article')->join('Category')->where('Category.Name', 'cat2')->findOne(); 
    631635$t->is($article->getTitle(), 'ccccc', 'join() allows to join to another table (many-to-one)'); 
     
    646650$nbArticles = sfPropelFinder::from('Article')->join('Comment')->where('Comment.Content', 'foo')->count(); 
    647651$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)'); 
    648654$article = sfPropelFinder::from('Article')->join('Comment')->where('Comment.Content', 'foo')->findOne(); 
    649655$t->is($article->getTitle(), 'bbbbb', 'join() allows to join to another table (one-to-many)'); 
     
    666672$article = sfPropelFinder::from('Article')->join('Comment')->join('Author')->where('Author.Name', 'John')->findOne(); 
    667673$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'); 
    668676$article = sfPropelFinder::from('Article')->joinComment()->joinAuthor()->where('Author.Name', 'John')->findOne(); 
    669677$t->is($article->getTitle(), 'aaaaa', 'joinXXX() does a join according to the XXX column name');