doctrine / data-fixtures

Doctrine2 ORM Data Fixtures Extensions
http://www.doctrine-project.org
MIT License
2.78k stars 224 forks source link

improve setReference/getReference with documentation or functionality #247

Open SimonHeimberg opened 7 years ago

SimonHeimberg commented 7 years ago

What I found out by trying is that setReference/getRefrence only support to store database entities. This should be improved that it is clear before trying.

Current behaviour:

suggestions

work around for transfering array of entities

set

$i=0;
foreach ($entities as $entity) {
    $this->setReference('some_reference_name_'.$i);
    ++$i;
}

get

$entities = array();
$i=0;
try {
    while (true) {
        $entities[] = $this->getReference('some_reference_name_'.$i);
        ++$i;
    }
} catch (\OutOfBoundsException $e) {
    //finished
}
Ocramius commented 7 years ago

improve the doc (on Readme) to mention the behaviour

Can be done in the docblock of the interface, IMO.

improve setReference to throw clear error messages when something invalid is passed (throw before getReference fails)

If we modify the docs, this is a must anyway.

support transfering an ArrayCollection with entities by setReference/getReference

I wouldn't do this, since it is still possible to persist/load anything (event Traversable implementations) if correctly implemented.