Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
markhuot committed Nov 22, 2023
1 parent 3fb915c commit 9fb7085
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/behaviors/SnapshotableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ public function toSnapshot()
->mapWithKeys(function ($field) {
return [$field->handle => $field];
})

// remove any ElementQueries from the element so we don't try to snapshot
// a serialized query. It will never match because it may have a dynamic `->where()`
// or an `->ownerId` that changes with each generated element.
->filter(fn ($field, $handle) => ! ($this->owner->{$handle} instanceof ElementQuery))

// snapshot any eager loaded element queries so nested elements are downcasted
// to a reproducible array
->map(function ($value, $handle) {
if ($this->owner->{$handle} instanceof ElementCollection) {
$value = $this->owner->{$handle};
Expand Down

0 comments on commit 9fb7085

Please sign in to comment.