symfony - How to save additional entity while persisting another in Doctrine? -
i've got place
entity , distance
one, so:
class place { /** @orm\id @orm\column(type="integer") @orm\generatedvalue(strategy="auto") */ private $id; /** @orm\column(type="string", length=62, nullable=false) */ private $name; /** @orm\onetomany(targetentity="distance", mappedby="origin") */ protected $distancesto; /** @orm\onetomany(targetentity="distance", mappedby="destination") */ protected $distancesfrom; } class distance { /** @orm\id @orm\column(type="integer") @orm\generatedvalue(strategy="auto") */ private $id; /** @orm\manytoone(targetentity="place", inversedby="distancesto") */ protected $origin; /** @orm\manytoone(targetentity="place", inversedby="distancesfrom") */ protected $destination; /** @orm\column(type="integer") */ private $miles; }
i want every time new distance
(from place_a place_b) saved, reverse distance (from place_b place_a) gets inserted in db. how can that?
you need create listener , listen persisting on distance
entity. while persists can create new distance
reverse route.
Comments
Post a Comment