Пример #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      ConnectionInterface $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(ConnectionInterface $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 corresponding 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->aWine !== null) {
             if ($this->aWine->isModified() || $this->aWine->isNew()) {
                 $affectedRows += $this->aWine->save($con);
             }
             $this->setWine($this->aWine);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
                 $affectedRows += 1;
             } else {
                 $affectedRows += $this->doUpdate($con);
             }
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Пример #2
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      ConnectionInterface $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(ConnectionInterface $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 corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aUserRelatedBySubmitter !== null) {
             if ($this->aUserRelatedBySubmitter->isModified() || $this->aUserRelatedBySubmitter->isNew()) {
                 $affectedRows += $this->aUserRelatedBySubmitter->save($con);
             }
             $this->setUserRelatedBySubmitter($this->aUserRelatedBySubmitter);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
                 $affectedRows += 1;
             } else {
                 $affectedRows += $this->doUpdate($con);
             }
             $this->resetModified();
         }
         if ($this->usersScheduledForDeletion !== null) {
             if (!$this->usersScheduledForDeletion->isEmpty()) {
                 $pks = array();
                 foreach ($this->usersScheduledForDeletion as $entry) {
                     $entryPk = [];
                     $entryPk[1] = $this->getIdWine();
                     $entryPk[0] = $entry->getIdUser();
                     $pks[] = $entryPk;
                 }
                 \WineTasting\Model\TastedWineQuery::create()->filterByPrimaryKeys($pks)->delete($con);
                 $this->usersScheduledForDeletion = null;
             }
         }
         if ($this->collUsers) {
             foreach ($this->collUsers as $user) {
                 if (!$user->isDeleted() && ($user->isNew() || $user->isModified())) {
                     $user->save($con);
                 }
             }
         }
         if ($this->usersRelatedByVote1ScheduledForDeletion !== null) {
             if (!$this->usersRelatedByVote1ScheduledForDeletion->isEmpty()) {
                 foreach ($this->usersRelatedByVote1ScheduledForDeletion as $userRelatedByVote1) {
                     // need to save related object because we set the relation to null
                     $userRelatedByVote1->save($con);
                 }
                 $this->usersRelatedByVote1ScheduledForDeletion = null;
             }
         }
         if ($this->collUsersRelatedByVote1 !== null) {
             foreach ($this->collUsersRelatedByVote1 as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->usersRelatedByVote2ScheduledForDeletion !== null) {
             if (!$this->usersRelatedByVote2ScheduledForDeletion->isEmpty()) {
                 foreach ($this->usersRelatedByVote2ScheduledForDeletion as $userRelatedByVote2) {
                     // need to save related object because we set the relation to null
                     $userRelatedByVote2->save($con);
                 }
                 $this->usersRelatedByVote2ScheduledForDeletion = null;
             }
         }
         if ($this->collUsersRelatedByVote2 !== null) {
             foreach ($this->collUsersRelatedByVote2 as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->usersRelatedByVote3ScheduledForDeletion !== null) {
             if (!$this->usersRelatedByVote3ScheduledForDeletion->isEmpty()) {
                 foreach ($this->usersRelatedByVote3ScheduledForDeletion as $userRelatedByVote3) {
                     // need to save related object because we set the relation to null
                     $userRelatedByVote3->save($con);
                 }
                 $this->usersRelatedByVote3ScheduledForDeletion = null;
             }
         }
         if ($this->collUsersRelatedByVote3 !== null) {
             foreach ($this->collUsersRelatedByVote3 as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->tastedWinesScheduledForDeletion !== null) {
             if (!$this->tastedWinesScheduledForDeletion->isEmpty()) {
                 \WineTasting\Model\TastedWineQuery::create()->filterByPrimaryKeys($this->tastedWinesScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->tastedWinesScheduledForDeletion = null;
             }
         }
         if ($this->collTastedWines !== null) {
             foreach ($this->collTastedWines as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }