Symfony2 Doctrine 合并 [英] Symfony2 Doctrine merge

查看:25
本文介绍了Symfony2 Doctrine 合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/working-with-associations.html 但我无法弄清楚级联合并的作用.我在别处看到过

I am studying https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/working-with-associations.html but I cannot figure out what cascade merge does. I have seen elsewhere that

$new_object = $em->merge($object); 

基本上是基于 $object 创建一个新的托管对象.对吗?

basically creates a new managed object based on $object. Is that correct?

推荐答案

$em->merge() 用于取出已脱离实体管理器上下文的实体并重新连接它".

$em->merge() is used to take an Entity which has been taken out of the context of the entity manager and 'reattach it'.

  • 如果实体从未被管理过,则合并相当于持久化.
  • 如果实体被分离或序列化(可能放在缓存中),那么合并或多或少会在数据存储中查找实体的 id,然后从那时起开始跟踪对实体的任何更改.

级联合并将此行为扩展到您要合并的实体的关联实体.这意味着更改会级联到关联,而不仅仅是被合并的实体.

Cascading a merge extends this behavior to associated entities of the one you are merging. This means that changes are cascaded to the associations and not just the entity being merged.

这篇关于Symfony2 Doctrine 合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆