data-import icon indicating copy to clipboard operation
data-import copied to clipboard

[DoctrineWriter] Get entity after writeItem() method call

Open fsevestre opened this issue 9 years ago • 0 comments

Hi guys,

I would like to be able to retrieve the entity persisted after calling writeItem on the DoctrineWriter.

Here is my use case:

$foos = array( // Will be a `FooEntity`
    'name' => 'foo',
    'bars' => array( // Will be a collection of `BarEntity` with a `foo` (`FooEntity`) property
        array(
            'title' => 'bar',
        ),
        array(
            'title' => 'bar2',
        )
    )
)


$fooWriter = new DoctrineWriter($entityManager, 'AppBundle:FooEntity');
$fooWriter->prepare();

$barWriter = new DoctrineWriter($entityManager, 'AppBundle:BarEntity');
$barWriter->prepare();

foreach ($foos as $foo) {
    $fooWriter->writeItem(
        array(
            'name' => $foo['name'],
        )
    )

    foreach ($foo['bars'] as $bar) {
        $barWriter->writeItem(
            array(
                 'foo' => ???? not possible ATM,
                 'title' => $bar['title'],
             )
    }
}

...

I'll open a PR.

Cheers

fsevestre avatar Oct 01 '15 19:10 fsevestre