Home » Php » php – Doctrine 2.1: how to set "cascade: persist" using yaml

php – Doctrine 2.1: how to set "cascade: persist" using yaml

Posted by: admin July 12, 2020 Leave a comment


I get an error when I try to do

$b = new B();

because I first need to persist $b, however I cannot do this, so I need to set cascade: persist I believe. I just cannot find in documentation how to do this using yaml schema.
Documentation does not cover this part ( I tried in other places in documentation as well)


How to&Answers:

This works for me

      targetEntity: Name
      mappedBy: product
      cascade: ["persist"]


If class A has an association, say, one-to-many to B, and the ArrayCollection variable in A is called $bcollection, then the YAML section for cascade={“persist”} would look like this:

      targetEntity: Entities\B
        - persist
      mappedBy: contact
      inversedBy: null
      orphanRemoval: false
      orderBy: null


If you tried cascade: ["persist"] and still not working here’s why.

As of 2016-08-28, I am using the latest version of doctrine at this time.
The doctrine persist is not working anymore because it is removed.

The main reason is you should not be changing the primary key of the connected table. And if you did, then why?

That is the reason the cascade persist is removed in YML Doctrine 2.

Reference: https://groups.google.com/forum/#!topic/doctrine-user/fdL7sgtjRM0