Beispiel #1
0
 /**
  * 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->aDiscipline !== null) {
             if ($this->aDiscipline->isModified() || $this->aDiscipline->isNew()) {
                 $affectedRows += $this->aDiscipline->save($con);
             }
             $this->setDiscipline($this->aDiscipline);
         }
         if ($this->aResultItem !== null) {
             if ($this->aResultItem->isModified() || $this->aResultItem->isNew()) {
                 $affectedRows += $this->aResultItem->save($con);
             }
             $this->setResultItem($this->aResultItem);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         if ($this->itemsScheduledForDeletion !== null) {
             if (!$this->itemsScheduledForDeletion->isEmpty()) {
                 $pks = array();
                 $pk = $this->getPrimaryKey();
                 foreach ($this->itemsScheduledForDeletion->getPrimaryKeys(false) as $remotePk) {
                     $pks[] = array($pk, $remotePk);
                 }
                 IngredientQuery::create()->filterByPrimaryKeys($pks)->delete($con);
                 $this->itemsScheduledForDeletion = null;
             }
             foreach ($this->getItems() as $item) {
                 if ($item->isModified()) {
                     $item->save($con);
                 }
             }
         }
         if ($this->ingredientsScheduledForDeletion !== null) {
             if (!$this->ingredientsScheduledForDeletion->isEmpty()) {
                 RecipeIngredientQuery::create()->filterByPrimaryKeys($this->ingredientsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->ingredientsScheduledForDeletion = null;
             }
         }
         if ($this->collIngredients !== null) {
             foreach ($this->collIngredients as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }