首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >信条:移除,然后保持独特的值

信条:移除,然后保持独特的值
EN

Stack Overflow用户
提问于 2016-07-18 17:16:31
回答 0查看 378关注 0票数 0

我有以下代码。Part的代码列需要一个唯一的值,因此当我remove(),然后使用相同的代码值persist()一行时,它会抛出一个错误。但是,应该先删除行,所以只有一个值。我必须在这些命令之间运行flush()吗?

代码语言:javascript
复制
        if ($existingPart) { # we found one
            if ($existingPart->getPrice() != $part->getPrice()) { # price changed
                $em->remove($existingPart); #soft-delete the old one
                $em->persist($part); # persist the new part
                $countUpdates++; # get number of updated entities
            }
        } else {
            $em->persist($part); # no existing part with same code, just add new part
            $count++; # get number of new commits    
        }                    
    }

    $em->flush();
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38432873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档