Development

Changeset 10543

You must first sign up to be able to contribute.

Changeset 10543

Show
Ignore:
Timestamp:
07/31/08 16:58:19 (4 months ago)
Author:
francois
Message:

sfPropelFinderPlugin Fixed problem with table alias and PostgreSQL (based on a patch by mrhyde) (closes #4104)

Files:

Legend:

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

    r10542 r10543  
    608608=== 2008-07-31 | Trunk === 
    609609 
     610 * francois: Fixed problem with table alias and PostgreSQL (based on a patch by mrhyde) 
    610611 * mrhyde: Fixed problem with group by clauses being ripped off by pager 
    611612 * francois: Implemented `DbFinder::toArray()`, `DbFinder::__toString()` and `DbFinder::toHtml()` 
  • plugins/sfPropelFinderPlugin/lib/sfPropelFinder.php

    r10542 r10543  
    517517    foreach($this->getWithColumns() as $alias => $column) 
    518518    { 
    519       $c->addAsColumn('\''.$alias.'\'', $column['column']); 
     519      if(strpos($alias, '.') !== false) 
     520      { 
     521        // The alias contains a forbidden character, so we must quote it 
     522        $alias = '"'.$alias.'"'; 
     523      } 
     524      $c->addAsColumn($alias, $column['column']); 
    520525    } 
    521526     
  • plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderRelationsTest.php

    r10540 r10543  
    7979$con = Propel::getConnection(); 
    8080 
    81 $t = new lime_test(78, new lime_output_color()); 
     81$t = new lime_test(79, new lime_output_color()); 
    8282 
    8383$t->diag('findRelation()'); 
     
    402402$comment->save(); 
    403403 
    404 $comment = sfPropelFinder::from('Comment')-> 
     404$finder = sfPropelFinder::from('Comment')-> 
    405405  join('Article')-> 
    406   withColumn('Article.Title')-> 
    407   findOne(); 
     406  withColumn('Article.Title'); 
     407$comment = $finder->findOne(); 
    408408$t->is($comment->getColumn('Article.Title'), 'bbbbb', 'Additional columns added with withColumn() are stored in the object and can be retrieved with getColumn()'); 
     409$t->is($finder->getLatestQuery(), 'SELECT comment.ID, comment.CONTENT, comment.ARTICLE_ID, comment.AUTHOR_ID, article.TITLE AS "Article.Title" FROM comment, article WHERE comment.ARTICLE_ID=article.ID LIMIT 1', 'Columns added with withColumn() can contain a dot (and are then escaped with double quotes in SQL)'); 
    409410 
    410411$comment = sfPropelFinder::from('Comment')-> 
     
    466467  orderBy('NbComments'); 
    467468$article = $finder->findOne(); 
    468 $t->is($finder->getLatestQuery(), 'SELECT article.ID, 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'); 
     469$t->is($finder->getLatestQuery(), 'SELECT article.ID, 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');