Skip to content

Commit

Permalink
Merge 717e2ad into 6a8ad35
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Aug 25, 2020
2 parents 6a8ad35 + 717e2ad commit 171bf36
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Form/DataTransformer/ModelToIdPropertyTransformer.php
Expand Up @@ -74,6 +74,7 @@ public function __construct(

public function reverseTransform($value)
{
/** @var ArrayCollection<array-key, object> $collection */
$collection = new ArrayCollection();

if (empty($value)) {
Expand All @@ -97,7 +98,7 @@ public function reverseTransform($value)
continue;
}

$collection[] = $this->modelManager->find($this->className, $id);
$collection->add($this->modelManager->find($this->className, $id));
}

return $collection;
Expand Down
3 changes: 2 additions & 1 deletion src/Form/DataTransformer/ModelsToArrayTransformer.php
Expand Up @@ -147,13 +147,14 @@ public function reverseTransform($keys)
throw new UnexpectedTypeException($keys, 'array');
}

/** @var ArrayCollection<array-key, object> $collection */
$collection = new ArrayCollection();
$notFound = [];

// optimize this into a SELECT WHERE IN query
foreach ($keys as $key) {
if ($model = $this->modelManager->find($this->class, $key)) {
$collection[] = $model;
$collection->add($model);
} else {
$notFound[] = $key;
}
Expand Down

0 comments on commit 171bf36

Please sign in to comment.