diff --git a/src/Controller/CustomerController.php b/src/Controller/CustomerController.php index c9c8e80a..9fd2aa7d 100644 --- a/src/Controller/CustomerController.php +++ b/src/Controller/CustomerController.php @@ -409,14 +409,14 @@ class CustomerController extends BaseController } // cleanup - if (count($vehicle_ids) > 0) + // delete all vehicles not in list + $cvs = $cust->getVehicles(); + foreach ($cvs as $cv) { - // delete all vehicles not in list - $cvs = $cust->getVehicles(); - foreach ($cvs as $cv) + if (!isset($vehicle_ids[$cv->getID()])) { - if (!isset($vehicle_ids[$cv->getID()])) - $em->remove($cv); + $cust->removeVehicle($cv); + $em->remove($cv); } } } @@ -458,15 +458,20 @@ class CustomerController extends BaseController $number_ids[] = $mobile_number->getID(); } + error_log('cleanup'); + // cleanup - if (count($number_ids) > 0) + // delete all not in list + $mns = $cust->getMobileNumbers(); + foreach ($mns as $mn) { - // delete all not in list - $mns = $cust->getMobileNumbers(); - foreach ($mns as $mn) + error_log($mn->getID()); + error_log(print_r($number_ids, true)); + if (!isset($number_ids[$mn->getID()])) { - if (!isset($number_ids[$mn->getID()])) - $em->remove($mn); + error_log('removing ' . $mn->getID()); + $cust->removeMobileNumber($mn); + $em->remove($mn); } } } diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index fb1b083b..68e10523 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -160,6 +160,12 @@ class Customer return $this; } + public function removeMobileNumber($num) + { + $this->numbers->removeElement($num); + return $this; + } + public function getMobileNumbers() { return $this->numbers; @@ -212,6 +218,12 @@ class Customer return $this; } + public function removeVehicle($vehicle) + { + $this->vehicles->removeElement($vehicle); + return $this; + } + public function getVehicles() { return $this->vehicles;