diff --git a/app/Models/Traits/UsesLinkedFields.php b/app/Models/Traits/UsesLinkedFields.php index 68be03d2..818fcf3a 100644 --- a/app/Models/Traits/UsesLinkedFields.php +++ b/app/Models/Traits/UsesLinkedFields.php @@ -293,8 +293,10 @@ private function syncRelation(string $property, string $inputType, $data, bool $ if ($model != null) { $model->update($entry); } else { - // protection against updating a deleted entry - unset($entry['uuid']); + // protection against clashing with a deleted entry + if (! empty($entry['uuid']) && $entity->$property()->onlyTrashed()->where('uuid', $entry['uuid'])->exists()) { + unset($entry['uuid']); + } $entity->$property()->create($entry); } } diff --git a/app/Models/V2/TreeSpecies/TreeSpecies.php b/app/Models/V2/TreeSpecies/TreeSpecies.php index ff4dc072..57054278 100644 --- a/app/Models/V2/TreeSpecies/TreeSpecies.php +++ b/app/Models/V2/TreeSpecies/TreeSpecies.php @@ -32,6 +32,7 @@ class TreeSpecies extends Model implements EntityRelationModel public $table = 'v2_tree_species'; protected $fillable = [ + 'uuid', 'name', 'amount', 'speciesable_type',