Skip to content

Commit

Permalink
[Form] ChoiceList query builder should return arrays
Browse files Browse the repository at this point in the history
ObjectChoiceList::initialize() is able to handle a Traversable object, which means getEntities() may safely return a cursor, but EntityChoiceList::getChoicesForValues() must return an array. To be consistent, return an array from both of these methods.

For what it's worth, the ORM seems to natively return arrays for the corresponding methods in ORMQueryBuilderLoader.

Note: Since ChoiceListInterface specifies that the arrays have "indices with ascending, 0-based numeric keys", strip the MongoCursor's document identifier keys by passing the results through array_values(). Ultimately, toArray() should be enhanced to allow passing a $use_keys argument to iterator_to_array().
  • Loading branch information
jmikola committed Feb 14, 2012
1 parent 60c0937 commit b1a9436
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Form/ChoiceList/MongoDBQueryBuilderLoader.php
Expand Up @@ -66,7 +66,7 @@ public function __construct($queryBuilder, ObjectManager $manager = null, $class
*/
public function getEntities()
{
return $this->queryBuilder->getQuery()->execute();
return array_values($this->queryBuilder->getQuery()->execute()->toArray());
}

/**
Expand All @@ -76,9 +76,11 @@ public function getEntitiesByIds($identifier, array $values)
{
$qb = clone ($this->queryBuilder);

return $qb
return array_values($qb
->field($identifier)->in($values)
->getQuery()
->execute();
->execute()
->toArray()
);
}
}

0 comments on commit b1a9436

Please sign in to comment.