/**
  * 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 corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aKategori !== null) {
             if ($this->aKategori->isModified() || $this->aKategori->isNew()) {
                 $affectedRows += $this->aKategori->save($con);
             }
             $this->setKategori($this->aKategori);
         }
         if ($this->aKemasan !== null) {
             if ($this->aKemasan->isModified() || $this->aKemasan->isNew()) {
                 $affectedRows += $this->aKemasan->save($con);
             }
             $this->setKemasan($this->aKemasan);
         }
         if ($this->aProdusen !== null) {
             if ($this->aProdusen->isModified() || $this->aProdusen->isNew()) {
                 $affectedRows += $this->aProdusen->save($con);
             }
             $this->setProdusen($this->aProdusen);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         if ($this->detailBarangMasuksScheduledForDeletion !== null) {
             if (!$this->detailBarangMasuksScheduledForDeletion->isEmpty()) {
                 DetailBarangMasukQuery::create()->filterByPrimaryKeys($this->detailBarangMasuksScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->detailBarangMasuksScheduledForDeletion = null;
             }
         }
         if ($this->collDetailBarangMasuks !== null) {
             foreach ($this->collDetailBarangMasuks as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->detailTransaksisScheduledForDeletion !== null) {
             if (!$this->detailTransaksisScheduledForDeletion->isEmpty()) {
                 DetailTransaksiQuery::create()->filterByPrimaryKeys($this->detailTransaksisScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->detailTransaksisScheduledForDeletion = null;
             }
         }
         if ($this->collDetailTransaksis !== null) {
             foreach ($this->collDetailTransaksis as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->hargasScheduledForDeletion !== null) {
             if (!$this->hargasScheduledForDeletion->isEmpty()) {
                 HargaQuery::create()->filterByPrimaryKeys($this->hargasScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->hargasScheduledForDeletion = null;
             }
         }
         if ($this->collHargas !== null) {
             foreach ($this->collHargas as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->linkBarangRaksScheduledForDeletion !== null) {
             if (!$this->linkBarangRaksScheduledForDeletion->isEmpty()) {
                 LinkBarangRakQuery::create()->filterByPrimaryKeys($this->linkBarangRaksScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->linkBarangRaksScheduledForDeletion = null;
             }
         }
         if ($this->collLinkBarangRaks !== null) {
             foreach ($this->collLinkBarangRaks as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->logBarangsScheduledForDeletion !== null) {
             if (!$this->logBarangsScheduledForDeletion->isEmpty()) {
                 LogBarangQuery::create()->filterByPrimaryKeys($this->logBarangsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->logBarangsScheduledForDeletion = null;
             }
         }
         if ($this->collLogBarangs !== null) {
             foreach ($this->collLogBarangs as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }