本文整理汇总了PHP中EntityManager::detach方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::detach方法的具体用法?PHP EntityManager::detach怎么用?PHP EntityManager::detach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityManager
的用法示例。
在下文中一共展示了EntityManager::detach方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: duplicate
/**
* Clones an entire tree and persists to database
*
* @param BlockOwnerInterface $block
*
* @return BlockOwnerInterface
*/
public function duplicate(BlockOwnerInterface $block)
{
$this->killDraftVersionFilter();
$this->killLoggableListener();
$blocks = $this->findByOwner($block);
array_unshift($blocks, $block);
// 1. Interate over all owned blocks and disconnect parents keeping ids
/** @var Block $descendant */
foreach ($blocks as $descendant) {
$descendant->originalId = $descendant->getId();
// if it has a parent we need to put it somewhere
if ($descendant->getParent()) {
$descendant->originalParentId = $descendant->getParent()->getId();
$descendant->setParent(null);
}
if ($descendant instanceof BlockContainerInterface) {
$descendant->setChildren(null);
}
$descendant->setOwner($block);
$descendant->setRootVersion(0);
$this->em->detach($descendant);
$this->em->persist($descendant);
}
$this->em->flush();
// 2. Iterate over all new blocks and reset their parents
foreach ($blocks as $descendant) {
if (isset($descendant->originalParentId)) {
foreach ($blocks as $parent) {
if ($descendant->originalParentId === $parent->originalId) {
$descendant->setParent($parent);
$parent->addChild($descendant);
}
}
}
}
$this->em->flush();
return $block;
}
示例2: detachAndPersist
/**
* For cloning purpose
*
* @param ContentInterface|\Opifer\EavBundle\Model\ValueSetInterface|\Opifer\EavBundle\Entity\Value $entity
*/
private function detachAndPersist($entity)
{
$this->em->detach($entity);
$this->em->persist($entity);
}