Doctrine 2.1: How to Set Cascade: Save Using yaml

I get an error when I try to do

$b = new B(); $a->addB($b); $entityManager->persist($a); 

because I need to save $ b first, but I cannot do this, so I need to set the cascade: persist, I believe. I just can't find in the documentation how to do this using the yaml scheme. The documentation does not cover this part (I also tried elsewhere in the documentation)

Greetings

+6
source share
3 answers

It works for me

 oneToMany: products: targetEntity: Name mappedBy: product cascade: ["persist"] 
+16
source

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

 oneToMany: bcollection: targetEntity: Entities\B cascade - persist mappedBy: contact inversedBy: null orphanRemoval: false orderBy: null 
0
source

If you tried cascade: ["persist"] and still did not work here why.

As of 2016-08-28, I am currently using the latest doctrine. The persist doctrine no longer works as it is removed .

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

For this reason, cascade persist is removed in YML Doctrine 2.

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

0
source

Source: https://habr.com/ru/post/900775/


All Articles