Changeset 10074
- Timestamp:
- 07/02/08 18:20:57 (5 months ago)
- Files:
-
- plugins/sfPropelFinderPlugin/README (modified) (1 diff)
- plugins/sfPropelFinderPlugin/lib/sfPropelFinder.php (modified) (2 diffs)
- plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfPropelFinderPlugin/README
r10068 r10074 408 408 where('Title', 'updated title')-> 409 409 count(); // 1 410 411 // Beware that set() updates all records found in a signle row 412 // And bypasses any behavior registered on the save() hooks 413 // You can force a one-by-one update by setting the second parameter to true 414 sfPropelFinder::from('Article')-> 415 set(array('Title' => 'updated title'), true); 416 // Beware that it may take a long time 410 417 }}} 411 418 plugins/sfPropelFinderPlugin/lib/sfPropelFinder.php
r10070 r10074 373 373 } 374 374 375 public function set($values, $ con = null, $reinitCriteria = true )375 public function set($values, $forceIndividualSaves = false, $con = null, $reinitCriteria = true ) 376 376 { 377 377 if (!is_array($values)) … … 379 379 throw new Exception('sfPropelFinder::set() expects an array as first argument'); 380 380 } 381 382 $find = $this->getCriteria(); 383 if (count($find->getJoins())) 384 { 385 throw new Exception('sfPropelFinder::set() does not support multitable updates, please do not use join'); 386 } 387 if($find->equals(new Criteria())) 388 { 389 // doUpdate will delete nothing when passed an empty criteria 390 // while it should, in fact, update all 391 $find = $this->addTrueCondition($find); 392 } 393 394 $set = new Criteria(); 395 foreach ($values as $columnName => $value) 396 { 397 $set->add($this->getColName($columnName), $value); 398 } 399 400 if(is_null($con)) $con = Propel::getConnection(); 401 $ret = BasePeer::doUpdate($find, $set, $con); 402 $this->updateLatestQuery($con); 403 if($reinitCriteria) 404 { 405 $this->reinitCriteria(); 406 } 407 408 return $ret; 381 if($forceIndividualSaves) 382 { 383 $objects = $this->find(null, $con, $reinitCriteria); 384 foreach ($objects as $object) 385 { 386 foreach ($values as $key => $value) 387 { 388 $object->setByName($key, $value); 389 } 390 $object->save(); 391 } 392 return count($objects); 393 } 394 else 395 { 396 $find = $this->getCriteria(); 397 if (count($find->getJoins())) 398 { 399 throw new Exception('sfPropelFinder::set() does not support multitable updates, please do not use join'); 400 } 401 if($find->equals(new Criteria())) 402 { 403 // doUpdate will delete nothing when passed an empty criteria 404 // while it should, in fact, update all 405 $find = $this->addTrueCondition($find); 406 } 407 408 $set = new Criteria(); 409 foreach ($values as $columnName => $value) 410 { 411 $set->add($this->getColName($columnName), $value); 412 } 413 414 if(is_null($con)) $con = Propel::getConnection(); 415 $ret = BasePeer::doUpdate($find, $set, $con); 416 $this->updateLatestQuery($con); 417 if($reinitCriteria) 418 { 419 $this->reinitCriteria(); 420 } 421 422 return $ret; 423 } 409 424 } 410 425 plugins/sfPropelFinderPlugin/test/unit/sfPropelFinderTest.php
r10070 r10074 65 65 ArticlePeer::doDeleteAll(); 66 66 67 $t = new lime_test(14 0, new lime_output_color());67 $t = new lime_test(142, new lime_output_color()); 68 68 69 69 $t->diag('find()'); … … 878 878 $t->is(sfPropelFinder::from('Article')->where('Title', 'updated title')->count(), 1, 'set() updates only the records found based on the array of values'); 879 879 880 $finder = sfPropelFinder::from('Article')->where('Title', 'bar'); 881 $t->is($finder->set(array('Title' => 'updated title'), true), 1, 'set() returns the number of updated rows, even with $forceIndividualSaves set to true'); 882 $t->is(sfPropelFinder::from('Article')->where('Title', 'updated title')->count(), 2, 'set() updates only the records found based on the array of values'); 883 880 884 try 881 885 {