Reputation: 61
I'm new with symfony2, and I started a project of blog. This project has two entities, one of posts (Noticia
) and one with comments (Comentario
).
I need to delete a post but I can't because of the relationship with comments.
Here is my attribute:
/**
* @ORM\ManyToOne(targetEntity="Noticia", inversedBy="comentarios", onDelete="SET NULL")
* @ORM\JoinColumn(name="noticia_id", referencedColumnName="id")
*/
private $noticia;
/**
* @ORM\OneToMany(targetEntity="Comentario", mappedBy="noticia")
*/
private $comentarios = array();
I tried to put onDelete="SET NULL"
but, when I updated my database with doctrine: php app/console doctrine:schema:update --force
I got this error:
The annotation @ORM\ManyToOne declared on property Noticia
Bundle\Entity\Comentario\::$noticia does not have a property named "onDelete".
Avaible properties: targetEntity, cascade, fetch, inversedBy
Upvotes: 1
Views: 2840
Reputation: 321
I believe that the onDelete="SET NULL" should be part of the JoinColumn annotation, not the ManyToOne annotation.
Upvotes: 7
Reputation: 23
One Way would be to search for all comments with the article relationship, you want to delete. So first delete all the comments, than the article itself. That a the eaysiest way without changing the annotation.
Upvotes: 0