stevenll
stevenll

Reputation: 1025

How to update changes done on entity inside an ArrayCollection

I have a User class which has different associations. When I create a new associated object, AClass, I do the following:

$object = new AClass();
$user->addAClass($object);
$userManager->updateUser($user);

The new object is persisted (created) in the database because I have used the option cascade: ['persist'] in the YML options file. What I fail to understand, is how to update (database wise) if I did something like this:

$AClasses = $user->getAClasses();
foreach ($AClasses as $object) {
    if ($object->hasCondition) {
        $object->setProperty($value);
    }
}
$userManager->updateUser($user);

I have tried cascade: ['refresh'] but all in void.

Upvotes: 2

Views: 1296

Answers (1)

Damaged Organic
Damaged Organic

Reputation: 8467

Code seems fine; try updating .yml and set persist like:

//A - in double quotes
cascade: ["persist"]

or

//B - new line
cascade
    - persist

or

//C - no quotes
cascade: [ persist ]

It's definitely .yml, as mine similar code works and looks just like yours (annotations based).

Upvotes: 1

Related Questions