/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aUser !== null) { if ($this->aUser->isModified() || $this->aUser->isNew()) { $affectedRows += $this->aUser->save($con); } $this->setUser($this->aUser); } if ($this->aItem !== null) { if ($this->aItem->isModified() || $this->aItem->isNew()) { $affectedRows += $this->aItem->save($con); } $this->setItem($this->aItem); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }
/** * Validates all modified columns of given User object. * If parameter $columns is either a single column name or an array of column names * than only those columns are validated. * * NOTICE: This does not apply to primary or foreign keys for now. * * @param User $obj The object to validate. * @param mixed $cols Column name or array of column names. * * @return mixed TRUE if all columns are valid or the error message of the first invalid column. */ public static function doValidate($obj, $cols = null) { $columns = array(); if ($cols) { $dbMap = Propel::getDatabaseMap(UserPeer::DATABASE_NAME); $tableMap = $dbMap->getTable(UserPeer::TABLE_NAME); if (!is_array($cols)) { $cols = array($cols); } foreach ($cols as $colName) { if ($tableMap->hasColumn($colName)) { $get = 'get' . $tableMap->getColumn($colName)->getPhpName(); $columns[$colName] = $obj->{$get}(); } } } else { if ($obj->isNew() || $obj->isColumnModified(UserPeer::USERNAME)) { $columns[UserPeer::USERNAME] = $obj->getUsername(); } if ($obj->isNew() || $obj->isColumnModified(UserPeer::EMAIL)) { $columns[UserPeer::EMAIL] = $obj->getEmail(); } } return BasePeer::doValidate(UserPeer::DATABASE_NAME, UserPeer::TABLE_NAME, $columns); }