Closed TiSiE closed 6 years ago
I had to use a different approach because setting new ArrayCollection($locations)
does not affect existing jobs.
perfect. Works now.
@TiSiE I tried $job->setLocations(new ArrayCollection($locations))
and it works now. Strange, I had to overlook something before.
I also changed the logic a bit. Locations are always set now. In my opinion it makes sense.
https://github.com/yawik/SimpleImport/blob/f917ac4183ccd064f488a107c029da2218abd740/src/Hydrator/JobHydrator.php#L60-L62
This works fine, if the job is a new entity, because getLocations() returns an ArrayCollection. But it fails on persisted entities, because it returns a Doctrine PersistentCollection then, which does not have the method fromArray.
Further on, even if this approach worked, it would append the locations, not replace.
You probably want to simply set a new Collection of locations in any case:
$job->setLocations(new ArrayCollection($locations))