diff --git a/packages/plugin/src/Elements/Db/EventQuery.php b/packages/plugin/src/Elements/Db/EventQuery.php index 8886e45..d5b105e 100644 --- a/packages/plugin/src/Elements/Db/EventQuery.php +++ b/packages/plugin/src/Elements/Db/EventQuery.php @@ -428,6 +428,7 @@ public function all($db = null): array $this->cacheToStorage(); $this->orderEvents($this->events); + $this->indexEvents($this->events); // Build up an event cache, to be accessed later $this->cacheEvents(); @@ -1231,6 +1232,19 @@ private function cutOffExcess(array &$array): void } } + private function indexEvents(array &$array): void + { + if ($this->indexBy) { + $index = []; + + foreach ($this->events as $event) { + $index[$event->{$this->indexBy}] = $event; + } + + $array = $index; + } + } + /** * Builds a cache of events for easy lookup with indexes. */