Skip to content

Commit

Permalink
Allow more than one relationship to be loaded via a variadic property…
Browse files Browse the repository at this point in the history
… argument on load
  • Loading branch information
thewunder committed Mar 25, 2024
1 parent 1e600df commit de70cdc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/ObjectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit de70cdc

Please sign in to comment.