data-import
data-import copied to clipboard
[DoctrineWriter] Get entity after writeItem() method call
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