From de70cdc8eb71e41e5f6866cfefef43331c414d39 Mon Sep 17 00:00:00 2001 From: Michael O'Connell Date: Mon, 25 Mar 2024 08:51:15 -0500 Subject: [PATCH] Allow more than one relationship to be loaded via a variadic property argument on load --- src/ObjectMapper.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ObjectMapper.php b/src/ObjectMapper.php index 2ff9fff..577e97f 100644 --- a/src/ObjectMapper.php +++ b/src/ObjectMapper.php @@ -185,16 +185,18 @@ public function findOneBy(string $objectName, array $criteria, ?array $orderBy = * Load a relationship on the provided objects. * * @param object[] $objects Objects to load a relationship on, can be of mixed class provided they all have a relationship on the same property - * @param string $property The name of a property to load a relationship on + * @param string[] $properties The name of one or more properties to load a relationship on * @return object[] The loaded objects keyed by id */ - public function load(array $objects, string $property): array + public function load(array $objects, string ...$properties): array { $relationshipManager = $this->getRelationshipManager(); $objectsByClass = $this->groupByClass($objects); $loadedObjects = []; foreach ($objectsByClass as $classObjects) { - $loadedObjects += $relationshipManager->load($classObjects, $property); + foreach ($properties as $property) { + $loadedObjects += $relationshipManager->load($classObjects, $property); + } } return $loadedObjects; }