ORM Doctrine ManyToOne on update CASCADE (Symfony)

前端 未结 1 922
别跟我提以往
别跟我提以往 2021-02-08 18:04

I have two entities

class Promotor
{

/**
 * @ORM\\ManyToOne(targetEntity=\"Ciudad\", inversedBy=\"promotor\")
 * @ORM\\JoinColumn(name=\"ciudad_id\", referenced         


        
相关标签:
1条回答
  • 2021-02-08 18:29

    The onDelete="CASCADE" is used on the database level. As you already said there is no onUpdate. Another downside is that ON DELETE CASCADE only works on InnoDB. It doesn't work on MyISAM.

    But you can use Doctrine in-memory cascade operations:

    class Promotor
    {
    
    /**
    * @ORM\ManyToOne(targetEntity="Ciudad", inversedBy="promotor", cascade={"persist", "remove"})
    * @ORM\JoinColumn(name="ciudad_id", referencedColumnName="id", nullable=false)
    */
    protected $ciudad;
    

    It's all described in the documentation: http://docs.doctrine-project.org/en/latest/reference/working-with-associations.html#transitive-persistence-cascade-operations

    Plus you can skip the JoinColumn annotation, because the way you have it written, is the default configuration and it's generated implicitly.

    So you can just write:

    class Promotor
    {
    
    /**
    * @ORM\ManyToOne(targetEntity="Ciudad", inversedBy="promotor", cascade={"persist", "remove"})
    */
    protected $ciudad;
    
    0 讨论(0)
提交回复
热议问题