什么级联“刷新”?在学说2中意味着什么? [英] What cascade "refresh" means in Doctrine 2?

查看:80
本文介绍了什么级联“刷新”?在学说2中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Doctrine2中级联的刷新是什么意思?是实体更新操作吗?



更新



现在看来,如果类别名称是更改后,所有相关产品将被获取和更新。但是,由于通常实体仅通过id关联,因此没有意义获取所有产品,因为在子表中没有任何要更新的内容。
出于这个原因,我想 refresh类似于MySQL的 ON UPDATE CASCADE-如果更改了父主键,则子值也将更改以反映这一点。因此,教义的刷新操作仅在ORM级别相同。而且只有在更新父母ID时才有意义,对吗?

解决方案

您可以找到文档此处,但作为总结,我将复制一些要点:


持久地保留,删除,分离,刷新和合并单个
实体可能变得非常麻烦,尤其是当高度
交织的对象图时参与了。因此,学说2通过级联这些
操作提供了
的传递持久性机制。每个与另一个实体的关联或
实体的集合都可以配置为自动级联某些
操作。默认情况下,没有级联操作。



存在以下级联选项:




  • persist:级联将操作持久化到关联实体。

  • 删除:级联将操作删除关联实体。

  • merge:级联将操作合并到关联实体

  • detach:层叠对关联实体的操作。

  • refresh:层叠对关联实体的刷新操作。


不需要复制所有部分,因为每个人都可以打开链接,但是从这一部分可以清楚地看到级联的想法。


根据原则对关联进行自动处理。


刷新级联案例,当您在 @oneToMany 关联上定义此级联时,您正在要求教义刷新集合刷新时,在许多方面都可以使用$ c>。


可以说我们在类别之间有一对多关联和 Product 实体。如果为其定义级联,则每次在其产品集合中的任何类别中调用刷新 将会刷新。



关于此部分问题:是实体更新操作吗?是,在刷新这意味着将数据源中的集合和实体提取到内存中。


级联操作在内存中执行。这意味着即使将要执行级联操作时,即使集合和与
相关的实体仍被标记为惰性,它们仍会被提取到内存中。
但是,这种方法允许针对每个操作执行实体生命周期事件。$

但是,将对象图拉入级联的内存可能会导致
的性能开销很大,尤其是当级联的
集合很大时。确保权衡您定义的每个级联操作的优点和缺点



What cascade "refresh" means in Doctrine2? Is it entity update operation?

UPDATE

Now it seems that if, for example, category name is changed, all related products will be fetched and updated. But, since usually entities are related only via id, there is no sense fetch all products, because there is nothing to update in child table. For this reason, I suppose that "refresh" is analogue of MySQL "ON UPDATE CASCADE" - if the parent primary key is changed, the child value will also change to reflect that. So Doctrine "refresh" operation is the same only in ORM level. And make sense only if we update parent id, am I right?

解决方案

You can find the documentation here, but for summary I will copy some important point:

Persisting, removing, detaching, refreshing and merging individual entities can become pretty cumbersome, especially when a highly interweaved object graph is involved. Therefore Doctrine 2 provides a mechanism for transitive persistence through cascading of these operations. Each association to another entity or a collection of entities can be configured to automatically cascade certain operations. By default, no operations are cascaded.

The following cascade options exist:

  • persist : Cascades persist operations to the associated entities.
  • remove : Cascades remove operations to the associated entities.
  • merge : Cascades merge operations to the associated entities.
  • detach : Cascades detach operations to the associated entities.
  • refresh : Cascades refresh operations to the associated entities.

Copying all the section is unnecessary since everybody can open the link but the idea of cascade is clear from this part.

doing some automatic stuff on associations by doctrine.

In refresh cascade case, when you define this cascade on a @oneToMany association, you are asking doctrine to refresh the collection on many side when you do refresh on one side.

lets say we have one-to-many association between Category and Product entities. If you define this cascade for it, everytime you invoke refresh on any Category its Products Collection will be refreshed.

About this part of your question: Is it entity update operation? yes, In Refresh It means fetching collections and entities from data source into the memory.

Cascade operations are performed in memory. That means collections and related entities are fetched into memory, even if they are still marked as lazy when the cascade operation is about to be performed. However this approach allows entity lifecycle events to be performed for each of these operations.

However, pulling objects graph into memory on cascade can cause considerable performance overhead, especially when cascading collections are large. Makes sure to weigh the benefits and downsides of each cascade operation that you define.

这篇关于什么级联“刷新”?在学说2中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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