什么级联“刷新"在教义 2 中是什么意思?
Doctrine2 中的级联刷新"是什么意思?是实体更新操作吗?
What cascade "refresh" means in Doctrine2? Is it entity update operation?
更新
现在看来,例如,如果更改类别名称,则会获取并更新所有相关产品.但是,由于通常实体仅通过 id 相关,因此获取所有产品没有意义,因为子表中没有任何可更新的内容.出于这个原因,我认为刷新"类似于 MySQLON UPDATE CASCADE"——如果父主键发生变化,子值也会发生变化以反映这一点.所以Doctrine刷新"操作仅在ORM级别是相同的.并且只有在我们更新父 ID 时才有意义,对吗?
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:
持久化、去除化、分离化、刷新化、融合化实体可能会变得非常麻烦,特别是当一个高度涉及交织的对象图.因此,教义 2 提供了一个通过级联这些的传递持久性机制操作.每个关联到另一个实体或集合实体可以配置为自动级联某些操作.默认情况下,没有级联操作.
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.
存在以下级联选项:
- persist :级联将操作持久化到关联的实体.
- remove :级联删除关联实体的操作.
- merge :将合并操作级联到关联实体.
- detach :将操作级联到关联的实体.
- refresh :将刷新操作级联到关联的实体.
复制所有部分是不必要的,因为每个人都可以打开链接,但是从这部分中可以清楚地看到级联的想法.
根据教义对关联做一些自动的事情.
在 refresh cascade
的情况下,当你在一个 @oneToMany
关联上定义这个级联时,你是在要求多方刷新 collection
在一侧做 refresh
.
假设我们在 Category
和 Product
实体之间有 一对多
关联.如果你为它定义了这个级联,每次你在任何 Category
上调用 refresh
都会刷新它的 Products Collection
.
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.
关于你的这部分问题:是实体更新操作吗?是的,在Refresh
中是指从数据源中获取集合和实体到内存中.
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.
相关文章