diff --git a/src/ObjectMapper.php b/src/ObjectMapper.php index 577e97f..1c271d2 100644 --- a/src/ObjectMapper.php +++ b/src/ObjectMapper.php @@ -194,9 +194,7 @@ public function load(array $objects, string ...$properties): array $objectsByClass = $this->groupByClass($objects); $loadedObjects = []; foreach ($objectsByClass as $classObjects) { - foreach ($properties as $property) { - $loadedObjects += $relationshipManager->load($classObjects, $property); - } + $loadedObjects += $relationshipManager->load($classObjects, ...$properties); } return $loadedObjects; } diff --git a/src/Relationship/RelationshipManager.php b/src/Relationship/RelationshipManager.php index 96b2576..5d52582 100644 --- a/src/Relationship/RelationshipManager.php +++ b/src/Relationship/RelationshipManager.php @@ -30,24 +30,30 @@ public function addHandler(RelationshipHandler $handler): void $this->handlers[$handler::getRelationshipClass()] = $handler; } - public function save(array $objects, string $property): void + public function save(array $objects, string ...$properties): void { if (empty($objects)) { return; } - $relationshipType = $this->readAttribute(reset($objects), $property); - $this->getHandler($relationshipType)->save($objects, $relationshipType); + foreach ($properties as $property) { + $relationshipType = $this->readAttribute(reset($objects), $property); + $this->getHandler($relationshipType)->save($objects, $relationshipType); + } } - public function load(array $objects, string $property): array + public function load(array $objects, string ...$properties): array { if (empty($objects)) { return []; } - $relationshipType = $this->readAttribute(reset($objects), $property); - return $this->getHandler($relationshipType)->load($objects, $relationshipType); + $loadedObjects = []; + foreach ($properties as $property) { + $relationshipType = $this->readAttribute(reset($objects), $property); + $loadedObjects += $this->getHandler($relationshipType)->load($objects, $relationshipType); + } + return $loadedObjects; } /**