Skip to content

Commit

Permalink
fix updating optionals when no property changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Aug 20, 2024
1 parent 0aa906a commit 7a055c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Fixed

- Updating an optional entity resulting in no property change no longer raised an exception when stored via SQL
- Updating an optional entity resulting in no property change no longer raised an exception when stored via SQL nor it generates an invalid document in Elasticsearch

## 3.1.1 - 2024-08-01

Expand Down
5 changes: 5 additions & 0 deletions src/Adapter/Elasticsearch/Encode.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ public function __invoke(Diff|Aggregate $data): Content
$properties = $this->properties($data->properties());
$entities = $data
->entities()
->exclude(static fn($entity) => $entity->properties()->empty())
->map(fn($entity) => [
$entity->name() => $this->properties($entity->properties()),
])
->toList();
$optionals = $data
->optionals()
->exclude(static fn($optional) => $optional->properties()->match(
static fn($properties) => $properties->empty(),
static fn() => false, // force setting the property to null below
))
->map(fn($optional) => [
$optional->name() => $optional->properties()->match(
$this->properties(...),
Expand Down

0 comments on commit 7a055c6

Please sign in to comment.