some more fixes for #55
This commit is contained in:
parent
834485fb4e
commit
3f28261159
3 changed files with 18 additions and 3 deletions
|
@ -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();
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue