Changeset 8160
- Timestamp:
- 03/30/08 21:54:21 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfPropelFinderPlugin/lib/sfPropelFinder.php
r8132 r8160 179 179 /** 180 180 * Finder Fluid Interface for Criteria::add() 181 *182 * @param string $critOrColumn The column to run the comparison on, or Criterion object.183 * @param mixed $value The value to be matched184 * @param string $comparison Comparison operator (leave empty for equal)185 *186 * @return sfPropelFinder the current finder object187 */188 public function where($critOrColumn, $value = null, $comparison = null)189 {190 $this->criteria->add($critOrColumn, $value, $comparison);191 192 return $this;193 }194 195 /**196 * Magic version of where()197 181 * Infers $column, $value, $comparison from $columnName and some optional arguments 198 182 * Examples: 199 * $articleFinder-> _where('IsPublished')183 * $articleFinder->where('IsPublished') 200 184 * => $c->add(ArticlePeer::IS_PUBLISHED, true) 201 * $articleFinder-> _where('CommentId', 3)185 * $articleFinder->where('CommentId', 3) 202 186 * => $c->add(ArticlePeer::COMMENT_ID, 3) 203 * $articleFinder-> _where('Title', 'like', '%foo')187 * $articleFinder->where('Title', 'like', '%foo') 204 188 * => $c->add(ArticlePeer::TITLE, '%foo', Criteria::LIKE) 205 189 * … … 209 193 * @return sfPropelFinder the current finder object 210 194 */ 211 public function _where($columnName, $arguments = array())195 public function where($columnName, $arguments = array()) 212 196 { 213 197 $column = $this->getColName($columnName); … … 233 217 throw new Exception('{sfPropelFinder} whereXXX can only be called with one or two arguments'); 234 218 } 235 236 return $this->where($column, $value, $comparison); 219 $this->criteria->add($column, $value, $comparison); 220 221 return $this; 222 237 223 } 238 224 … … 240 226 * Finder Fluid Interface for Criteria::addAscendingOrderByColumn() 241 227 * and Criteria::addDescendingOrderByColumn() 242 */243 public function orderBy($column, $order = Criteria::ASC)244 {245 switch ($order)246 {247 case Criteria::ASC:248 $this->criteria->addAscendingOrderByColumn($column);249 break;250 case Criteria::DESC:251 $this->criteria->addDescendingOrderByColumn($column);252 break;253 default:254 throw new Exception('{sfPropelFinder} orderBy only accepts "asc" or "desc" as argument');255 }256 257 return $this;258 }259 260 /**261 * Magic version of orderBy()262 228 * Infers $column and $order from $columnName and some optional arguments 263 229 * Examples: 264 * $articleFinder-> _orderBy('CreatedAt')230 * $articleFinder->orderBy('CreatedAt') 265 231 * => $c->addAscendingOrderByColumn(ArticlePeer::CREATED_AT) 266 * $articlefinder-> _orderBy('CategoryId', 'desc')232 * $articlefinder->orderBy('CategoryId', 'desc') 267 233 * => $c->addDescendingOrderByColumn(ArticlePeer::CATEGORY_ID) 268 234 */ 269 public function _orderBy($columnName, $arguments = array())235 public function orderBy($columnName, $arguments = array()) 270 236 { 271 237 $column = $this->getColName($columnName); … … 276 242 } 277 243 278 return $this->orderBy($column, $order); 244 switch ($order) 245 { 246 case Criteria::ASC: 247 $this->criteria->addAscendingOrderByColumn($column); 248 break; 249 case Criteria::DESC: 250 $this->criteria->addDescendingOrderByColumn($column); 251 break; 252 default: 253 throw new Exception('{sfPropelFinder} orderBy only accepts "asc" or "desc" as argument'); 254 } 255 256 return $this; 279 257 } 280 258 281 259 /** 282 260 * Finder Fluid Interface for Criteria::addJoin() 283 */284 public function join($column1, $column2, $operator = null)285 {286 $this->criteria->addJoin($column1, $column2, $operator);287 288 return $this;289 }290 291 /**292 * Magic version of join()293 261 * Infers $column1, $column2 and $operator from $relatedClass and some optional arguments 294 262 * Uses the Propel column maps, based on the schema, to guess the related columns 295 263 * Examples: 296 * $articleFinder-> _join('Comment')264 * $articleFinder->join('Comment') 297 265 * => $c->addJoin(ArticlePeer::ID, CommentPeer::ARTICLE_ID) 298 * $articleFinder-> _join('Category', 'RIGHT JOIN')266 * $articleFinder->join('Category', 'RIGHT JOIN') 299 267 * => $c->addJoin(ArticlePeer::CATEGORY_ID, CategoryPeer::ID, Criteria::RIGHT_JOIN) 300 268 */ 301 public function _join($relatedClass, $arguments = array())269 public function join($relatedClass, $arguments = array()) 302 270 { 303 271 list($column1, $column2) = $this->getRelation($relatedClass); … … 308 276 $operator = null; 309 277 } 310 311 return $this->join($column1, $column2, $operator); 278 $this->criteria->addJoin($column1, $column2, $operator); 279 280 return $this; 312 281 } 313 282 … … 385 354 if(strpos($name, 'where') === 0) 386 355 { 387 return $this-> _where(substr($name, 5), $arguments);356 return $this->where(substr($name, 5), $arguments); 388 357 } 389 358 if(strpos($name, 'orderBy') === 0) 390 359 { 391 return $this-> _orderBy(substr($name, 7), $arguments);360 return $this->orderBy(substr($name, 7), $arguments); 392 361 } 393 362 if(strpos($name, 'join') === 0) 394 363 { 395 return $this-> _join(substr($name, 4), $arguments);364 return $this->join(substr($name, 4), $arguments); 396 365 } 397 366 if(method_exists($this->criteria, $name)) plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderTest.php
r8132 r8160 357 357 $article3->setCategory($category2); 358 358 $article3->save(); 359 $nbArticles = sfPropelFinder::from('Article')->joinCategory()->where (CategoryPeer::NAME,'cat1')->count();359 $nbArticles = sfPropelFinder::from('Article')->joinCategory()->whereCategory_Name('cat1')->count(); 360 360 $t->is($nbArticles, 2, 'joinXXX() allows to join to another table (many-to-one)'); 361 $nbArticles = sfPropelFinder::from('Article')->joinCategory()->where (CategoryPeer::NAME,'cat2')->count();361 $nbArticles = sfPropelFinder::from('Article')->joinCategory()->whereCategory_Name('cat2')->count(); 362 362 $t->is($nbArticles, 1, 'joinXXX() allows to join to another table (many-to-one)'); 363 $article = sfPropelFinder::from('Article')->joinCategory()->where (CategoryPeer::NAME,'cat2')->findOne();363 $article = sfPropelFinder::from('Article')->joinCategory()->whereCategory_Name('cat2')->findOne(); 364 364 $t->is($article->getTitle(), 'ccccc', 'joinXXX() allows to join to another table (many-to-one)'); 365 365 ArticlePeer::doDeleteAll(); … … 377 377 $comment->setArticle($article2); 378 378 $comment->save(); 379 $nbArticles = sfPropelFinder::from('Article')->joinComment()->where (CommentPeer::CONTENT,'foo')->count();379 $nbArticles = sfPropelFinder::from('Article')->joinComment()->whereComment_Content('foo')->count(); 380 380 $t->is($nbArticles, 1, 'joinXXX() allows to join to another table (one-to-many)'); 381 $article = sfPropelFinder::from('Article')->joinComment()->where (CommentPeer::CONTENT,'foo')->findOne();381 $article = sfPropelFinder::from('Article')->joinComment()->whereComment_Content('foo')->findOne(); 382 382 $t->is($article->getTitle(), 'bbbbb', 'joinXXX() allows to join to another table (one-to-many)'); 383 383 … … 397 397 $comment->setAuthor($author1); 398 398 $comment->save(); 399 $article = sfPropelFinder::from('Article')->joinComment()->joinAuthor()->where (AuthorPeer::NAME,'John')->findOne();399 $article = sfPropelFinder::from('Article')->joinComment()->joinAuthor()->whereAuthor_Name('John')->findOne(); 400 400 $t->is($article->getTitle(), 'aaaaa', 'you can chain several joinXXX() statements'); 401 401