Changeset 9889
- Timestamp:
- 06/26/08 12:36:05 (5 years ago)
- Files:
-
- plugins/sfPropelFinderPlugin/README (modified) (4 diffs)
- plugins/sfPropelFinderPlugin/lib/sfPropelFinder.php (modified) (4 diffs)
- plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfPropelFinderPlugin/README
r9884 r9889 225 225 <?php 226 226 $article = sfPropelFinder::from('Article')-> 227 join('Category )->227 join('Category')-> 228 228 withColumn('Category_Name')-> 229 229 findOne(); … … 238 238 }}} 239 239 240 Just like `with()`, `withColumn()` will add an internal join automatically (based on the TableMap) if you don't do it yourself in the finder: 241 {{{ 242 #!php 243 <?php 244 $article = sfPropelFinder::from('Article')-> 245 withColumn('Category_Name')-> 246 findOne(); 247 $categoryName = $article->getColumn('Category_Name'); // Works without a call to `join('Category')` 248 }}} 249 250 240 251 This `withColumn()` method can use a column alias as second argument. 241 252 {{{ … … 243 254 <?php 244 255 $article = sfPropelFinder::from('Article')-> 245 join('Category )->256 join('Category')-> 246 257 withColumn('Category_Name', 'category')-> 247 258 findOne(); … … 265 276 <?php 266 277 $article = sfPropelFinder::from('Article')-> 267 join('Category )->278 join('Category')-> 268 279 withColumn('Category_CreatedAt', 'CategoryCreatedAt', 'Timestamp')-> 269 280 findOne(); plugins/sfPropelFinderPlugin/lib/sfPropelFinder.php
r9884 r9889 299 299 foreach($this->getWithColumns() as $name => $column) 300 300 { 301 // if the column is on a related object property 302 // and if join() wasn't called previously on this object, do a simple join 303 $peerClass = $column['peerClass']; 304 if($peerClass && !in_array($peerClass, $this->relations)) 305 { 306 list($column1, $column2) = $this->getRelation(str_replace('Peer', '', $peerClass)); 307 $c->addJoin($column1, $column2); 308 $this->relations[]= $peerClass; 309 } 301 310 $c->addAsColumn($name, $column['column']); 302 311 } … … 374 383 } 375 384 } 385 if($isCalculationColumn) 386 { 387 $peerClass = null; 388 } 389 else 390 { 391 list($peerClass, $columnName) = $this->getColName($column, null, true); 392 } 376 393 $this->withColumns [$alias]= array( 377 'column' => $isCalculationColumn ? $column : $this->getColName($column), 378 'type' => $type 394 'column' => $isCalculationColumn ? $column : $columnName, 395 'type' => $type, 396 'peerClass' => $peerClass 379 397 ); 380 398 … … 669 687 } 670 688 671 protected function getColName($phpName, $peerClass = null )689 protected function getColName($phpName, $peerClass = null, $withPeerClass = false) 672 690 { 673 691 if(array_key_exists($phpName, $this->withColumns)) … … 687 705 { 688 706 $column = call_user_func(array($peerClass, 'translateFieldName'), $phpName, BasePeer::TYPE_PHPNAME, BasePeer::TYPE_COLNAME); 689 return $ column;707 return $withPeerClass ? array($peerClass, $column) : $column; 690 708 } 691 709 catch (PropelException $e) plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderTest.php
r9884 r9889 63 63 ArticlePeer::doDeleteAll(); 64 64 65 $t = new lime_test( 99, new lime_output_color());65 $t = new lime_test(100, new lime_output_color()); 66 66 67 67 $t->diag('find()'); … … 568 568 569 569 $comment = sfPropelFinder::from('Comment')-> 570 withColumn('Article_Title')-> 571 findOne(); 572 $t->is($comment->getColumn('Article_Title'), 'bbbbb', 'If withColumn() is called on a related object column with no join on this class, the finder adds the join automatically'); 573 574 $comment = sfPropelFinder::from('Comment')-> 570 575 join('Article')-> 571 576 withColumn('Article_Title', 'ArticleTitle')->