Skip to content

Instantly share code, notes, and snippets.

@jpetitcolas
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpetitcolas/10367887 to your computer and use it in GitHub Desktop.
Save jpetitcolas/10367887 to your computer and use it in GitHub Desktop.
Issue with Document Manager
<?php
// Controller
$tag = new Tag();
$dm->persist($tag);
$dm->flush();
$this->getContainer()->get('my_service')->import($content, $tag);
// Service
public function import(Content $content, Tag $tag)
{
// With following line, it works.
$tag = $this->contentRepository->getDocumentManager()->find(null, $tag->getId());
// Otherwise:
// A detached document was found through a reference during cascading a persist operation: my-tag (tag-id)
$content->addTag($tag);
$this->contentRepository->getDocumentManager()->flush();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment