I have a model where `$entSolicitudUsuario` can have one|many `$entProductoSolicitud` and `$entProductoSolicitud` can have one|many `$entFacturaProductoSolicitud`. I need to delete a complete `$entSolicitudUsuario` so I will need to remove all the relations. This is how I'm doing:

// Find the $entSolicitudUsuario for remove later should be the last one

$entSolicitudUsuario = $em->getRepository("AppBundle:SolicitudUsuario")->find($solicitud);

// Find each $entProductosSolicitud attached to the current $entSolicitudUsuario

$entProductosSolicitud = $em->getRepository("AppBundle:ProductoSolicitud")->findBy(
        array('solicitud_usuario' => $entSolicitudUsuario->getId())
     );

    foreach($entProductosSolicitud as $productoSolicitud) {

// Find each $entFacturaProductoSolicitud attached to the current $productoSolicitud
        // and perform the remove the flush will be outside the loop

$entFacturaProductoSolicitud = $em->getRepository("AppBundle:FacturaProductoSolicitud")->findByProductoSolicitud($productoSolicitud->getId());
        $em->remove($entFacturaProductoSolicitud);
    }

My question is, should I do it on this way or exists a better one? For see the entity for `FacturaProductoSolicitud` below:

    class FacturaProductoSolicitud
    {
        use IdentifierAutogeneratedEntityTrait;
        /**
* @ORM\Column(name="no_factura", type="string", length=50, nullable=false)
         */
        protected $no_factura;

        /**
         * @ORM\Column(name="fecha", type="datetime", nullable=false)
         */
        protected $fecha;

        /**
         * @ORM\ManyToOne(targetEntity="ProductoSolicitud")
* @ORM\JoinColumn(name="producto_solicitud_id", referencedColumnName="id")
         */
        protected $producto_solicitud;

        // Setter and getter methods
    }

If exists a ManyToOne relationship, can I take advantage of this by doing a cascade? I mean what should happen if I add `cascade={"persist", "remove"}` to the `ManyToOne` relationship when I delete a `$entSolicitudUsuario`? Can any point me on the right direction?

--
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to