Skip to content

Commit

Permalink
Merge pull request #628 from wri/fix/TM-1581-tree-collections
Browse files Browse the repository at this point in the history
[TM-1581] Improve BE mechanics for updating tree collections.
  • Loading branch information
roguenet authored Dec 19, 2024
2 parents 48be67b + d75fd98 commit 082ab4e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/Models/Traits/UsesLinkedFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
1 change: 1 addition & 0 deletions app/Models/V2/TreeSpecies/TreeSpecies.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class TreeSpecies extends Model implements EntityRelationModel
public $table = 'v2_tree_species';

protected $fillable = [
'uuid',
'name',
'amount',
'speciesable_type',
Expand Down

0 comments on commit 082ab4e

Please sign in to comment.