/**
  * 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->aFittingRuleEntityRelatedByForkedid !== null) {
             if ($this->aFittingRuleEntityRelatedByForkedid->isModified() || $this->aFittingRuleEntityRelatedByForkedid->isNew()) {
                 $affectedRows += $this->aFittingRuleEntityRelatedByForkedid->save($con);
             }
             $this->setFittingRuleEntityRelatedByForkedid($this->aFittingRuleEntityRelatedByForkedid);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
                 $affectedRows += 1;
             } else {
                 $affectedRows += $this->doUpdate($con);
             }
             $this->resetModified();
         }
         if ($this->fittingRuleEntitiesRelatedByIdScheduledForDeletion !== null) {
             if (!$this->fittingRuleEntitiesRelatedByIdScheduledForDeletion->isEmpty()) {
                 foreach ($this->fittingRuleEntitiesRelatedByIdScheduledForDeletion as $fittingRuleEntityRelatedById) {
                     // need to save related object because we set the relation to null
                     $fittingRuleEntityRelatedById->save($con);
                 }
                 $this->fittingRuleEntitiesRelatedByIdScheduledForDeletion = null;
             }
         }
         if ($this->collFittingRuleEntitiesRelatedById !== null) {
             foreach ($this->collFittingRuleEntitiesRelatedById as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->fittingRuleRowsScheduledForDeletion !== null) {
             if (!$this->fittingRuleRowsScheduledForDeletion->isEmpty()) {
                 \ECP\FittingRuleRowQuery::create()->filterByPrimaryKeys($this->fittingRuleRowsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->fittingRuleRowsScheduledForDeletion = null;
             }
         }
         if ($this->collFittingRuleRows !== null) {
             foreach ($this->collFittingRuleRows as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->rulesetFilterRulesScheduledForDeletion !== null) {
             if (!$this->rulesetFilterRulesScheduledForDeletion->isEmpty()) {
                 \ECP\RulesetFilterRuleQuery::create()->filterByPrimaryKeys($this->rulesetFilterRulesScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->rulesetFilterRulesScheduledForDeletion = null;
             }
         }
         if ($this->collRulesetFilterRules !== null) {
             foreach ($this->collRulesetFilterRules as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * 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;
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
                 $affectedRows += 1;
             } else {
                 $affectedRows += $this->doUpdate($con);
             }
             $this->resetModified();
         }
         if ($this->combinationCollTypeIdsScheduledForDeletion !== null) {
             if (!$this->combinationCollTypeIdsScheduledForDeletion->isEmpty()) {
                 $pks = array();
                 foreach ($this->combinationCollTypeIdsScheduledForDeletion as $combination) {
                     $entryPk = [];
                     $entryPk[2] = $this->getId();
                     $entryPk[1] = $combination[0]->getId();
                     //$combination[1] = Id;
                     $entryPk[0] = $combination[1];
                     $pks[] = $entryPk;
                 }
                 \ECP\TypeComparisonQuery::create()->filterByPrimaryKeys($pks)->delete($con);
                 $this->combinationCollTypeIdsScheduledForDeletion = null;
             }
         }
         if (null !== $this->combinationCollTypeIds) {
             foreach ($this->combinationCollTypeIds as $combination) {
                 //$combination[0] = Type (typecomparison_fk_af1a2f)
                 if (!$combination[0]->isDeleted() && ($combination[0]->isNew() || $combination[0]->isModified())) {
                     $combination[0]->save($con);
                 }
                 //$combination[1] = Id; Nothing to save.
             }
         }
         if ($this->typeComparisonsScheduledForDeletion !== null) {
             if (!$this->typeComparisonsScheduledForDeletion->isEmpty()) {
                 \ECP\TypeComparisonQuery::create()->filterByPrimaryKeys($this->typeComparisonsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->typeComparisonsScheduledForDeletion = null;
             }
         }
         if ($this->collTypeComparisons !== null) {
             foreach ($this->collTypeComparisons as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->fittingRuleRowsRelatedByConcatenationScheduledForDeletion !== null) {
             if (!$this->fittingRuleRowsRelatedByConcatenationScheduledForDeletion->isEmpty()) {
                 foreach ($this->fittingRuleRowsRelatedByConcatenationScheduledForDeletion as $fittingRuleRowRelatedByConcatenation) {
                     // need to save related object because we set the relation to null
                     $fittingRuleRowRelatedByConcatenation->save($con);
                 }
                 $this->fittingRuleRowsRelatedByConcatenationScheduledForDeletion = null;
             }
         }
         if ($this->collFittingRuleRowsRelatedByConcatenation !== null) {
             foreach ($this->collFittingRuleRowsRelatedByConcatenation as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->fittingRuleRowsRelatedByComparisonScheduledForDeletion !== null) {
             if (!$this->fittingRuleRowsRelatedByComparisonScheduledForDeletion->isEmpty()) {
                 \ECP\FittingRuleRowQuery::create()->filterByPrimaryKeys($this->fittingRuleRowsRelatedByComparisonScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->fittingRuleRowsRelatedByComparisonScheduledForDeletion = null;
             }
         }
         if ($this->collFittingRuleRowsRelatedByComparison !== null) {
             foreach ($this->collFittingRuleRowsRelatedByComparison as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->itemFilterRulesRelatedByConcatenationScheduledForDeletion !== null) {
             if (!$this->itemFilterRulesRelatedByConcatenationScheduledForDeletion->isEmpty()) {
                 foreach ($this->itemFilterRulesRelatedByConcatenationScheduledForDeletion as $itemFilterRuleRelatedByConcatenation) {
                     // need to save related object because we set the relation to null
                     $itemFilterRuleRelatedByConcatenation->save($con);
                 }
                 $this->itemFilterRulesRelatedByConcatenationScheduledForDeletion = null;
             }
         }
         if ($this->collItemFilterRulesRelatedByConcatenation !== null) {
             foreach ($this->collItemFilterRulesRelatedByConcatenation as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->itemFilterRulesRelatedByComparisonScheduledForDeletion !== null) {
             if (!$this->itemFilterRulesRelatedByComparisonScheduledForDeletion->isEmpty()) {
                 \ECP\ItemFilterRuleQuery::create()->filterByPrimaryKeys($this->itemFilterRulesRelatedByComparisonScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->itemFilterRulesRelatedByComparisonScheduledForDeletion = null;
             }
         }
         if ($this->collItemFilterRulesRelatedByComparison !== null) {
             foreach ($this->collItemFilterRulesRelatedByComparison as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->rulesetFilterRulesRelatedByConcatenationScheduledForDeletion !== null) {
             if (!$this->rulesetFilterRulesRelatedByConcatenationScheduledForDeletion->isEmpty()) {
                 foreach ($this->rulesetFilterRulesRelatedByConcatenationScheduledForDeletion as $rulesetFilterRuleRelatedByConcatenation) {
                     // need to save related object because we set the relation to null
                     $rulesetFilterRuleRelatedByConcatenation->save($con);
                 }
                 $this->rulesetFilterRulesRelatedByConcatenationScheduledForDeletion = null;
             }
         }
         if ($this->collRulesetFilterRulesRelatedByConcatenation !== null) {
             foreach ($this->collRulesetFilterRulesRelatedByConcatenation as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->rulesetFilterRulesRelatedByComparisonScheduledForDeletion !== null) {
             if (!$this->rulesetFilterRulesRelatedByComparisonScheduledForDeletion->isEmpty()) {
                 \ECP\RulesetFilterRuleQuery::create()->filterByPrimaryKeys($this->rulesetFilterRulesRelatedByComparisonScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->rulesetFilterRulesRelatedByComparisonScheduledForDeletion = null;
             }
         }
         if ($this->collRulesetFilterRulesRelatedByComparison !== null) {
             foreach ($this->collRulesetFilterRulesRelatedByComparison as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }