예제 #1
0
 /**
  * Issue an UPDATE query based the current ModelCriteria and a list of changes.
  * This method is called by ModelCriteria::update() inside a transaction.
  *
  * @param array               $values               Associative array of keys and values to replace
  * @param ConnectionInterface $con                  a connection object
  * @param boolean             $forceIndividualSaves If false (default), the resulting call is a Criteria::doUpdate(), otherwise it is a series of save() calls on all the found objects
  *
  * @return integer Number of updated rows
  */
 public function doUpdate($values, ConnectionInterface $con, $forceIndividualSaves = false)
 {
     if ($forceIndividualSaves) {
         // Update rows one by one
         $objects = $this->setFormatter(ModelCriteria::FORMAT_OBJECT)->find($con);
         foreach ($objects as $object) {
             foreach ($values as $key => $value) {
                 $object->setByName($key, $value);
             }
         }
         $objects->save($con);
         $affectedRows = count($objects);
     } else {
         // update rows in a single query
         if ($values instanceof Criteria) {
             $set = $values;
         } else {
             $set = new Criteria($this->getDbName());
             foreach ($values as $columnName => $value) {
                 $realColumnName = $this->getTableMap()->getColumnByPhpName($columnName)->getFullyQualifiedName();
                 $set->add($realColumnName, $value);
             }
         }
         $affectedRows = parent::doUpdate($set, $con);
         if ($this->getTableMap()->extractPrimaryKey($this)) {
             // this criteria updates only one object defined by a concrete primary key,
             // therefore there's no need to remove anything from the pool
         } else {
             call_user_func(array($this->modelTableMapName, 'clearInstancePool'));
             call_user_func(array($this->modelTableMapName, 'clearRelatedInstancePool'));
         }
     }
     return $affectedRows;
 }
예제 #2
0
 /**
  * Issue an UPDATE query based the current ModelCriteria and a list of changes.
  * This method is called by ModelCriteria::update() inside a transaction.
  *
  * @param array               $values               Associative array of keys and values to replace
  * @param ConnectionInterface $con                  a connection object
  * @param boolean             $forceIndividualSaves If false (default), the resulting call is a Criteria::doUpdate(), otherwise it is a series of save() calls on all the found objects
  *
  * @return integer Number of updated rows
  */
 public function doUpdate($values, $con, $forceIndividualSaves = false)
 {
     if ($forceIndividualSaves) {
         // Update rows one by one
         $objects = $this->setFormatter(ModelCriteria::FORMAT_OBJECT)->find($con);
         foreach ($objects as $object) {
             foreach ($values as $key => $value) {
                 $object->setByName($key, $value);
             }
         }
         $objects->save($con);
         $affectedRows = count($objects);
     } else {
         // update rows in a single query
         if ($values instanceof Criteria) {
             $set = $values;
         } else {
             $set = new Criteria($this->getDbName());
             foreach ($values as $columnName => $value) {
                 $realColumnName = $this->getTableMap()->getColumnByPhpName($columnName)->getFullyQualifiedName();
                 $set->add($realColumnName, $value);
             }
         }
         $affectedRows = parent::doUpdate($set, $con);
         call_user_func(array($this->modelTableMapName, 'clearInstancePool'));
         call_user_func(array($this->modelTableMapName, 'clearRelatedInstancePool'));
     }
     return $affectedRows;
 }