yawik / SimpleImport

Simple Job Import Module. Imports job openings into YAWIK
MIT License
0 stars 1 forks source link

Setting locations fails on updates. #8

Closed TiSiE closed 6 years ago

TiSiE commented 6 years ago

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))

fedys commented 6 years ago

I had to use a different approach because setting new ArrayCollection($locations) does not affect existing jobs.

cbleek commented 6 years ago

perfect. Works now.

fedys commented 6 years ago

@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.