DDC-1128: Entity not being deleted on @ManyToOne - no errors whatsoever. #1410

Closed
opened 2026-01-22 13:13:30 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 27, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user nriesco:

If I try to delete an entity that has @ManyToOne relationships, nothing happens, not even a constraint error.

   $em->remove($respuestas[$i]);
   $em->flush();
   // clear() doesn't help at all

In fact this DQL works perfectly fine:

   $em->createQuery('DELETE FROM \models\respuesta s WHERE s.id=2'  );

The code:

<?php
namespace models;
use Doctrine\Common\Collections\ArrayCollection;

/****
 * @Entity
 * @Table(name="respuesta",indexes={@index(name="fk*respuesta_usuario1",columns={"usuario_id"}),@index(name="fk_respuesta_respuestaTipo1",columns={"respuestaTipo_id"}),@index(name="fk_respuesta_respuestaFuente1",columns={"respuestaFuente*id"})})
 */
class Respuesta {
    /**** 
     * @Id @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**** 
     * @Column(type="integer",nullable=true)
     */
    private $scan_original;

    /****
     * @ManyToOne(targetEntity="Usuario", inversedBy="Respuesta")
     */
    private $usuario;

    /****
     * @ManyToOne(targetEntity="RespuestaTipo", inversedBy="Respuesta")
     */
    private $respuestaTipo;

    /****
     * @ManyToOne(targetEntity="RespuestaFuente", inversedBy="Respuesta")
     */
    private $respuestaFuente;

    public function **construct(){}

    public function setId($id){
         $this->id = $id;
         return $this; // fluent interface
    }

    public function getId(){
         return $this->id;
    }

    public function setUsuario(Usuario $usuario){
         $usuario->addRespuesta($this);
         $this->usuario = $usuario;
         return $this; // fluent interface
    }

    public function getUsuario(){
         return $this->usuario;
    }

    public function setRespuestaTipo(RespuestaTipo $respuestaTipo){
         $respuestaTipo->addRespuesta($this);
         $this->respuestaTipo = $respuestaTipo;
         return $this; // fluent interface
    }

    public function getRespuestaTipo(){
         return $this->respuestaTipo;
    }

    public function setRespuestaFuente(RespuestaFuente $respuestaFuente){
         $respuestaFuente->addRespuesta($this);
         $this->respuestaFuente = $respuestaFuente;
         return $this; // fluent interface
    }

    public function getRespuestaFuente(){
         return $this->respuestaFuente;
    }
}
?>
Originally created by @doctrinebot on GitHub (Apr 27, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user nriesco: If I try to delete an entity that has @ManyToOne relationships, nothing happens, not even a constraint error. ``` $em->remove($respuestas[$i]); $em->flush(); // clear() doesn't help at all ``` In fact this DQL works perfectly fine: ``` $em->createQuery('DELETE FROM \models\respuesta s WHERE s.id=2' ); ``` The code: ``` <?php namespace models; use Doctrine\Common\Collections\ArrayCollection; /**** * @Entity * @Table(name="respuesta",indexes={@index(name="fk*respuesta_usuario1",columns={"usuario_id"}),@index(name="fk_respuesta_respuestaTipo1",columns={"respuestaTipo_id"}),@index(name="fk_respuesta_respuestaFuente1",columns={"respuestaFuente*id"})}) */ class Respuesta { /**** * @Id @Column(type="integer") * @GeneratedValue(strategy="AUTO") */ private $id; /**** * @Column(type="integer",nullable=true) */ private $scan_original; /**** * @ManyToOne(targetEntity="Usuario", inversedBy="Respuesta") */ private $usuario; /**** * @ManyToOne(targetEntity="RespuestaTipo", inversedBy="Respuesta") */ private $respuestaTipo; /**** * @ManyToOne(targetEntity="RespuestaFuente", inversedBy="Respuesta") */ private $respuestaFuente; public function **construct(){} public function setId($id){ $this->id = $id; return $this; // fluent interface } public function getId(){ return $this->id; } public function setUsuario(Usuario $usuario){ $usuario->addRespuesta($this); $this->usuario = $usuario; return $this; // fluent interface } public function getUsuario(){ return $this->usuario; } public function setRespuestaTipo(RespuestaTipo $respuestaTipo){ $respuestaTipo->addRespuesta($this); $this->respuestaTipo = $respuestaTipo; return $this; // fluent interface } public function getRespuestaTipo(){ return $this->respuestaTipo; } public function setRespuestaFuente(RespuestaFuente $respuestaFuente){ $respuestaFuente->addRespuesta($this); $this->respuestaFuente = $respuestaFuente; return $this; // fluent interface } public function getRespuestaFuente(){ return $this->respuestaFuente; } } ?> ```
admin added the Bug label 2026-01-22 13:13:30 +01:00
admin closed this issue 2026-01-22 13:13:30 +01:00
Author
Owner

@doctrinebot commented on GitHub (Apr 30, 2011):

Comment created by @beberlei:

Fixed formatting, schedule for 2.0.5

@doctrinebot commented on GitHub (Apr 30, 2011): Comment created by @beberlei: Fixed formatting, schedule for 2.0.5
Author
Owner

@doctrinebot commented on GitHub (May 1, 2011):

Comment created by @beberlei:

I cannot reproduce this, can you upload an xdebug function trace starting before $em->remove() and stopping after $em->flush() ?

@doctrinebot commented on GitHub (May 1, 2011): Comment created by @beberlei: I cannot reproduce this, can you upload an xdebug function trace starting before $em->remove() and stopping after $em->flush() ?
Author
Owner

@doctrinebot commented on GitHub (May 3, 2011):

Comment created by nriesco:

error1.log.xt is the xdebug function trace.
error2.log.xt is the same but with a lot more information (xdebug.collect_return=On)

@doctrinebot commented on GitHub (May 3, 2011): Comment created by nriesco: error1.log.xt is the xdebug function trace. error2.log.xt is the same but with a lot more information (xdebug.collect_return=On)
Author
Owner

@doctrinebot commented on GitHub (May 14, 2011):

Comment created by @beberlei:

The entity is not managed, are you fetching it from the session? It has to be managed, call $entity = $em->merge($entity); before calling $em->remove($entity);

@doctrinebot commented on GitHub (May 14, 2011): Comment created by @beberlei: The entity is not managed, are you fetching it from the session? It has to be managed, call $entity = $em->merge($entity); before calling $em->remove($entity);
Author
Owner

@doctrinebot commented on GitHub (May 14, 2011):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (May 14, 2011): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1410