jeudi 4 décembre 2014

Silex + Doctrine ORM @HasLifecycleCallbacks @MappedSuperclass does not fire


Vote count:

0




I am using Silex with Doctrine ORM, everything was working properly but I got a problem than i cant figure out.


I have an Entity news in the NS Lpdq\Model\Entity which extends another class News in the NS Lpdq\Model which contains some methods and pre/post event methods for doctrine.



<?php

namespace Lpdq\Model\Entity;

/**
* News
*
* @Table(name="news")
* @Entity(repositoryClass="Lpdq\Model\Entity\Repository\News")
*/
class News extends Lpdq\Model\News{
/*some properties/methods*/
}

<?php

namespace Lpdq\Model;
/**
* News
*
* @MappedSuperclass
* @HasLifecycleCallbacks
*/
class News{

/**
* @PrePersist
*/
public function prePersist()
{
$this->setCreated(new DateTime());
$this->setUpdated(new DateTime());
}

/**
* @PreUpdate
*/
public function preUpdate()
{
$this->setUpdated(new DateTime());
}

/*...some methods...*/


}


In have a controller like that



<?php

namespace Lpdq\Controller;

use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Lpdq\Model\Entity\News;

class EpisodeController {

public function addAction( Request $request, Application $app) {
$news = new news();
$news->setTitle('test');
/*...*/
$app['orm.em']->persist($news);
$app['orm.em']->flush();

/*...*/
}
}


My problem is that my prePersist/preUpdate methods are not called when I persist my entity ? (so I get an error because my properties created and updated are null)?


If I set my entity News as HasLifecycleCallbacks and put the same prePersist/Update method.. they are triggered


while I am here, I am wondering if the way I extends my entities to put pre/post and other methods are a good or bad practice ?



asked 35 secs ago







Silex + Doctrine ORM @HasLifecycleCallbacks @MappedSuperclass does not fire

Aucun commentaire:

Enregistrer un commentaire