Modifies conditions of hasOne and hasMany associations

If multiple delete flags are configured for model, then $active=true doesn't
do anything - you have to alter conditions in association definition

@param object $model
@param mixed $active
487502
protected function _softDeleteAssociations($model, $active) {
		if (empty($model->belongsTo)) {
			return;
		}

		$fields = array_keys($this->_normalizeFields($model));
		$parentModels = array_keys($model->belongsTo);

		foreach ($parentModels as $parentModel) {
			foreach (array('hasOne', 'hasMany') as $assocType) {
				if (empty($model->{$parentModel}->{$assocType})) {
					continue;
				}

				foreach ($model->{$parentModel}->{$assocType} as $assoc => $assocConfig) {
					$modelName = empty($assocConfig['className']) ? $assoc : @$assocConfig['className'];
					if ((!empty($model->plugin) && strstr($model->plugin . '.', $model->alias) === false ? $model->plugin . '.' : '') . $model->alias !== $modelName) {
						continue;
					}

					$conditions =& $model->{$parentModel}->{$assocType}[$assoc]['conditions'];
					if (!is_array($conditions)) {
						$model->{$parentModel}->{$assocType}[$assoc]['conditions'] = array();
					}

					$multiFields = 1 < count($fields);
					foreach ($fields as $field) {
						if ($active) {
							if (!isset($conditions[$field]) && !isset($conditions[$assoc . '.' . $field])) {
								if (is_string($active)) {
									if ($field == $active) {
										$conditions[$assoc . '.' . $field] = false;
									} elseif (isset($conditions[$assoc . '.' . $field])) {
										unset($conditions[$assoc . '.' . $field]);
									}
								} elseif (!$multiFields) {
									$conditions[$assoc . '.' . $field] = false;
								}
							}
						} elseif (isset($conditions[$assoc . '.' . $field])) {
							unset($conditions[$assoc . '.' . $field]);
						}
					}
				}
			}
		}
	}
331290
def delete_activities_for_entity_model(model)
      Activr.registry.activity_entities_for_model(model.class).each do |entity_name|
        self.driver.delete_activities(:entities => { entity_name => model.id })
      end
    end
55604
public function remove(Builder $builder, Model $model)
    {
        $query      = $builder->getQuery();
        $column     = $model->getQualifiedActiveColumn();
        $bindingKey = 0;

        foreach ((array) $query->wheres as $key => $where) {

            if ($this->isActiveConstraint($where, $column)) {

                $this->removeWhere($query, $key);
                $this->removeBinding($query, $bindingKey);
            }

            if ( ! in_array($where['type'], ['Null', 'NotNull'])) {
                $bindingKey++;
            }
        }
    }
1099553
public function delete(Identifiable $model)
    {
        $this->checkIsModel($model);
        $this->publish('deleting', $model);
        $model->delete();
        $this->publish('deleted', $model);
    }
127664
public function setActive($active = true)
    {
        $this->active = (bool) $active;

        if ($active) {
            $this->setHtmlAttribute('class', 'active');
        }

        return $this;
    }
234770
public function delete(AbstractModel $model)
    {
        $array = $model->toArrayCurrent();

        if (empty($array)) {
            throw new \Exception('Error : delete used an empty model');
        }

        return $this->tableGateway->delete($array);
    }
986001
public function setActive($active = true)
    {
        if (is_callable($active)) {
            $this->active = $active($this);

            return $this;
        }

        $this->active = (bool) $active;

        return $this;
    }
295574
public function cleanup(Model $model) {
        if ($model->id) {
            $this->resetCache($model, $model->id);
        }

        foreach ($this->_cached as $key => $value) {
            $this->deleteCache($model, $key);
        }
    }
369488
protected function shouldCommit(Model $model)
    {
        $state = $model->getState();
        return $model->isDirty() || $state->is('new') || $state->is('deleting');
    }
1129534
public function clearCache(Model $model) {
        if ($this->_cached) {
            foreach ($this->_cached as $key => $value) {
                $this->deleteCache($model, $key);
            }
        }

        return Cache::clear(false, $this->settings[$model->alias]['cacheConfig']);
    }
859028
public function removeAssociation(Association $association)
    {
        if ($this->associations->contains($association)) {
            $this->associations->removeElement($association);
        }
    }
481478
public function deleted($model)
    {
        $translationRepository = \App::make(TranslationRepository::class);
        foreach ($model->translatableAttributes() as $attribute) {
            $translationRepository->deleteByCode($model->translationCodeFor($attribute));
        }
    }
1082835
public function delete($model)
    {
        if ($this->hasNotProvided($this->condition))
            return "To prevent deleting all records you must provide at least one condition. Using where method would solve this.";

        $ids = $this->search($model);

        //If string it can't continue for retrieving models
        //Throw exception with the error.
        if (is_string($ids))
            throw new OdooException($ids);

        return $this->deleteById($model, $ids);
    }
33604
public function apply(Builder $builder, Model $model)
    {
        $column = $model->getQualifiedActiveColumn();

        $builder->where($column, true);

        $this->addWithInactive($builder);
    }
1049495
public function checkModel(ActiveRecord $model)
    {
        /** @var TrackableBehavior $behavior */
        if (($behavior = $this->getBehavior($model)) === null) {
            return null;
        }

        $auditTableName = $behavior->auditTableName;

        if (($pos=strpos($auditTableName, '.')) !== false) {
            $auditSchema = substr($auditTableName, 0, $pos);
        } else {
            $auditSchema = null;
        }
        $triggerTemplate = $this->triggerTemplate($model->getTableSchema()->name, $auditSchema);

        return [
            'enabled' => true,
            'valid' => $triggerTemplate['exists'],
        ];
    }
1051417
public function beforeSave(Model $Model, $options = array()) {
		$currentData = false;
		if ($this->config[$Model->alias]['merge'] && (isset($Model->data[$Model->alias][$Model->primaryKey]) || isset($Model->data[$Model->primaryKey]))) {
			$Model->recursive = -1;
			$currentData = $Model->find('first',
				array(
					'conditions' => array($Model->primaryKey => (isset($Model->data[$Model->alias][$Model->primaryKey]) ? $Model->data[$Model->alias][$Model->primaryKey] : $Model->data[$Model->primaryKey])),
					'fields' => $this->config[$Model->alias]['fields']
				)
			);
		}
		foreach ($this->config[$Model->alias]['fields'] as $field) {
			if (isset($Model->data[$Model->alias][$field])) {
				if ($currentData) {
					$Model->data[$Model->alias][$field] = array_replace_recursive((array)$currentData[$Model->alias][$field], (array)$Model->data[$Model->alias][$field]);
				}
				$Model->data[$Model->alias][$field] = $this->_serialize($Model->alias, $Model->data[$Model->alias][$field]);
			} elseif (isset($Model->data[$field])) {
				if ($currentData) {
					$Model->data[$field] = array_replace_recursive($currentData[$Model->alias][$field], $Model->data[$field]);
				}
				$Model->data[$field] = $this->_serialize($Model->alias, $Model->data[$field]);
			}
		}
		return true;
	}
1354349
public static function deleteModel($model)
    {
        foreach(AnnotationManager::getPropertiesAnnotations(BeanFactory::getObjectClass($model), RelationBase::class) as $propertyName => $annotations)
        {
            if(null === $model[$propertyName])
            {
                continue;
            }
            $annotation = $annotations[0];
            Delete::parse($model, $propertyName, $annotation);
        }
    }