gpt4 book ai didi

php - 级联 "refresh"在 Doctrine 2 中意味着什么?

转载 作者:行者123 更新时间:2023-12-05 08:33:55 27 4
gpt4 key购买 nike

级联“刷新”在 Doctrine2 中意味着什么?是实体更新操作吗?

更新

现在看来,例如,如果更改类别名称,将获取并更新所有相关产品。但是,由于通常实体仅通过 id 相关,因此获取所有产品是没有意义的,因为子表中没有要更新的内容。出于这个原因,我认为“刷新”类似于 MySQL“ON UPDATE CASCADE”——如果父主键发生变化,子值也会发生变化以反射(reflect)这一点。所以 Doctrine 的“刷新”操作只在 ORM 级别是相同的。并且只有在我们更新父 ID 时才有意义,对吗?

最佳答案

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

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.

不需要复制所有部分,因为每个人都可以打开链接,但是级联的概念从这部分就很清楚了。

根据学说对协会做一些自动的事情。

refresh cascade 情况下,当您在 @oneToMany 关联上定义此级联时,您要求原则在多方面刷新 collection 当您在一侧执行 refresh

假设我们在 CategoryProduct 实体之间有一对多关联。如果您为其定义此级联,则每次您在任何 Category 上调用 refresh 时,其 Products Collection 都会被刷新。

关于你的这部分问题:是实体更新操作吗?是的,在Refresh中是指从数据源中获取集合和实体到内存中。

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.

关于php - 级联 "refresh"在 Doctrine 2 中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34897830/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com