Closed rbruhn closed 6 years ago
I looked at where the error is occurring:
SoftCascade.php
protected function run($models)
{
$models = collect($models);
if ($models->count() > 0) {
$model = $models->first();
if (!in_array($model->getConnectionName(), $this->connectionsToTransact)) {
$this->connectionsToTransact[] = $model->getConnectionName();
DB::connection($model->getConnectionName())->beginTransaction();
}
if (!is_object($model)) {
return;
}
if (!$this->isCascadable($model)) {
return;
}
$this->relations($model, $models->pluck($model->getKeyName()));
}
}
Basically, MongoDB doesn't have transactions. A simple work around would be to change the checks so they occur before creating the transaction
protected function run($models)
{
$models = collect($models);
if ($models->count() > 0) {
$model = $models->first();
if (!is_object($model)) {
return;
}
if (!$this->isCascadable($model)) {
return;
}
if (!in_array($model->getConnectionName(), $this->connectionsToTransact)) {
$this->connectionsToTransact[] = $model->getConnectionName();
DB::connection($model->getConnectionName())->beginTransaction();
}
$this->relations($model, $models->pluck($model->getKeyName()));
}
}
Merged in 5.5.13
I get the following error when trying to delete a record. The model in question does not use SoftCascade. However, there two other models higher in the hierarchy that do. For example, I have Project => Expedition => Subject relationships where if a Project or Expedition is deleted, soft cascade handles deleting all the subjects. The subjects are in MongoDB and use jenssegers/laravel-mongodb package.
I've not had an issue with this until recently. Has something changed?