diff --git a/lib/Controller/EntityController.php b/lib/Controller/EntityController.php index 29b88e3..44edf8e 100644 --- a/lib/Controller/EntityController.php +++ b/lib/Controller/EntityController.php @@ -71,6 +71,10 @@ class EntityController extends Controller { */ public function delete($identifier) { $entity = $this->get($identifier); + + if ($entity instanceof Model\Channel) { + $entity->clearData($this->em); + } $this->em->remove($entity); $this->em->flush(); diff --git a/lib/Model/Channel.php b/lib/Model/Channel.php index 3f246b3..0954a76 100644 --- a/lib/Model/Channel.php +++ b/lib/Model/Channel.php @@ -49,14 +49,25 @@ class Channel extends Entity { $this->data = new ArrayCollection(); $this->groups = new ArrayCollection(); } - + /** * Add a new data to the database - * @todo move to Logger\Logger? */ public function addData(\Volkszaehler\Model\Data $data) { $this->data->add($data); } + + + /** + * Purge data + * + * prevents doctrine of using single delete statements + * @todo filter from & to + */ + public function clearData(\Doctrine\ORM\EntityManager $em) { + $sql = 'DELETE FROM data WHERE channel_id = ?'; + return $em->getConnection()->executeQuery($sql, array($this->id)); + } } ?> diff --git a/lib/Model/Entity.php b/lib/Model/Entity.php index 25197da..c59faba 100644 --- a/lib/Model/Entity.php +++ b/lib/Model/Entity.php @@ -59,7 +59,7 @@ abstract class Entity { protected $type; /** - * @OneToMany(targetEntity="Property", mappedBy="entity", cascade={"persist"}, orphanRemoval=true) + * @OneToMany(targetEntity="Property", mappedBy="entity", cascade={"remove", "persist"}, orphanRemoval=true) * @OrderBy({"key" = "ASC"}) */ protected $properties = NULL;