Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

php - What cascade "refresh" means in Doctrine 2?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...