Clone entity in CASCADE mode

怎甘沉沦 提交于 2019-12-08 08:19:02

问题


I need to find a object in DB by some parameters, lets take ID as example then I have this entity:

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use AppBundle\Model\IdentifierAutogeneratedEntityTrait;
use DateTime;

/**
 * @ORM\Entity
 * @ORM\Table(name="negocio.solicitud_usuario", schema="negocio")
 * @ORM\Entity(repositoryClass="AppBundle\Entity\Repository\SolicitudUsuarioRepository")
 */
class SolicitudUsuario
{
    use IdentifierAutogeneratedEntityTrait;

    /**
     * @ORM\ManyToOne(targetEntity="SolicitudUsuario", cascade={"persist", "remove"})
     * @ORM\JoinColumn(name="padre_id", referencedColumnName="id")
     */
    protected $padre;

    /**
     * @var ArrayCollection
     * @ORM\OneToMany(targetEntity="ProductoSolicitud", mappedBy="solicitud_usuario")
     */
    protected $producto_solicitud;

    /**
    * @var ArrayCollection
    * @ORM\OneToMany(targetEntity="Constancia", mappedBy="solicitud_usuario")
    */
    protected $constancias;


    /**
     * @ORM\ManyToOne(targetEntity="Usuario", cascade={"persist"})
     * @ORM\JoinColumn(name="usuario_id", referencedColumnName="id")
     */
    protected $usuario;

    /**
     * @ORM\ManyToOne(targetEntity="TipoTramite", cascade={"persist"})
     * @ORM\JoinColumn(name="tipo_tramite_id", referencedColumnName="id")
     */
    protected $tipo_tramite;

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

    /**
     * @ORM\ManyToOne(targetEntity="TipoRegistro", cascade={"persist"})
     * @ORM\JoinColumn(name="tipo_registro_id", referencedColumnName="id")
     */
    protected $tipo_registro;

    /**
     * @ORM\ManyToOne(targetEntity="EstadoSolicitud", cascade={"persist"})
     * @ORM\JoinColumn(name="estado_solicitud_id", referencedColumnName="id")
     */
    protected $estado_solicitud;

    /**
     * @ORM\Column(name="diferencia_pago", type="decimal", precision=6, scale=2, nullable=false)
     */
    protected $diferencia_pago;

    /**
     * @ORM\ManyToOne(targetEntity="OficinaRegional", cascade={"persist"})
     * @ORM\JoinColumn(name="oficina_regional_id", referencedColumnName="id", nullable=true)
     */
    protected $oficina_regional;   
}

That entity has a lot of relations as you may already notice and also the related entities has other relations and so on. How, finding just SolicitudUsuario I clone the current record|object keeping integrity? Take a look to this example:

  • Find SolicitudUsuario by ID=1
  • Record found
    • Clone current SolicitudUSuario entity and all it's related entities to a new one.
    • The new record will have padre=1

Any advice? It's clear what I want to achieve?

来源:https://stackoverflow.com/questions/28650001/clone-entity-in-cascade-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!