Search code examples
doctrine-ormflow-framework

typo3 flow persist updated relation


I have an issue TYPO3 Flow updating my relations. Am I wrong, that Flow should update changed relations automatically, so I don't have to update the related entities with the respective repository?

Example 1:
I have a model "Project" with multiple "Job" childs on attribute "jobs". If I do:

$project->setJobs($collectionOfJobs);
$this->projectRepository->update($project);

then jobs are not updated correctly with the new project-id.

Example 2:
I wanted to realize a bidirectional one-to-one relationship between the models "Project" and "Briefing" and found out, that there is a known bug in TYPO3: Bidirectional One-To-One Relationships in Flow

So I wanted to to fix it with setting the relation on the other side manually:

class Briefing {    

 /**
  * @param \Some\Package\Domain\Model\Project $project
  * @return void
  */
 public function setProject($project) {
   $this->project = $project;
   $this->project->setBriefing($this);
   $this->projectRepository->update($this->project); // FIXME: Bug? Flow should do this
 }

but I had to update the relation with its repository by self. Shouldn't Flow do this automatically?

So do I really need to update each child with its repository by self or should Flow do this for me?

Environment:
- TYPO3 FLOW 2.3.3 (latest stable)
- Doctrine 2.3.6
- PHP 5.4.39-0+deb7u2


Solution

  • From the Flow manual:

    When you add or remove an object to or from a repository, the object will be added to or removed from the underlying persistence as expected upon persistAll. But what about changes to already persisted objects? As we have seen, those changes are only persisted, if the changed object is given to update on the corresponding repository.

    Now, for objects that have no corresponding repository, how are changes persisted? In the same way you fetch those objects from their parent - by traversal. TYPO3 Flow follows references from objects managed in a repository (aggregate roots) for all persistence operations, unless the referenced object itself is an aggregate root.

    So if there is a repository for your entity, you must explicitely call the update method. This was different originally but changed for Flow 1.0.

    Maybe you think that this should work because it worked in TYPO3 CMS Extbase < 6.2 until it was changed there, too.