From c477f52b58427713aa1aedf195dda2db218ed556 Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Wed, 18 Dec 2024 11:58:26 -0800 Subject: [PATCH 1/2] [TM-1581] Respect the UUID the client sends when creating. --- app/Models/Traits/UsesLinkedFields.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Models/Traits/UsesLinkedFields.php b/app/Models/Traits/UsesLinkedFields.php index 68be03d2a..818fcf3ac 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); } } From d75fd98e2500a4c9755d9e4b1674c73149b0de5b Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Wed, 18 Dec 2024 15:06:39 -0800 Subject: [PATCH 2/2] [TM-1581] To actually use the UUID from the client, it needs to be fillable on the model. --- app/Models/V2/TreeSpecies/TreeSpecies.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Models/V2/TreeSpecies/TreeSpecies.php b/app/Models/V2/TreeSpecies/TreeSpecies.php index ff4dc0729..57054278b 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',