Reputation: 7693
I get an error when I try to do
$b = new B();
$a->addB($b);
$entityManager->persist($a);
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)
Cheers
Upvotes: 7
Views: 10673
Reputation: 3166
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
Upvotes: 0
Reputation: 7693
This works for me
oneToMany:
products:
targetEntity: Name
mappedBy: product
cascade: ["persist"]
Upvotes: 18
Reputation: 1245
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:
oneToMany:
bcollection:
targetEntity: Entities\B
cascade
- persist
mappedBy: contact
inversedBy: null
orphanRemoval: false
orderBy: null
Upvotes: 0