DDC-22: EntityManager#refresh() should also refresh associations. #28

Closed
opened 2026-01-22 12:24:48 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 25, 2009).

Jira issue originally created by user romanb:

Initially this issue was brought up by DC-41 which in turn led to DDC-21. The implementation of DDC-21 requires a working refresh() implementation that also refreshes associations.

  1. For the state of the entity that is refreshed itself this is self-explanatory (simple select on the primary table, this is what already works).

  2. For single-valued associations the proper query depends on whether the entity being refreshed represents the owning side or the inverse side of the association. If it is the inverse side, a simple query like this should do:

select addresses.id, ... from addresses where addresses.user_id=?

If it is the owning side, a join may be required:

select addresses.id, ... from addresses inner join users on addresses.id = users.address_id where users.id=?
  1. For one-to-many collections, a simple select on the target entity table, similar to the following should do:
select .... from phonenumbers ... where phonenumbers.user_id=?

For many-to-many collections a similar select that joins over the join table is required.

An clever way for collections might be to not trigger this SQL immediately on refresh() but to simply mark the collection as uninitialized again so that the first access would trigger the reload, similar to a lazy-load.

Note that the collection itself is refreshed, not the state of the entities contained therein.
Also note that only associations need to be refreshed that were already initialized. If an associated collection is uninitialized, it does not need to be refreshed. If an associated single-valued proxy is uninitialized, it does not need to be refreshed.

Originally created by @doctrinebot on GitHub (Sep 25, 2009). Jira issue originally created by user romanb: Initially this issue was brought up by DC-41 which in turn led to [DDC-21](http://www.doctrine-project.org/jira/browse/DDC-21). The implementation of [DDC-21](http://www.doctrine-project.org/jira/browse/DDC-21) requires a working refresh() implementation that also refreshes associations. 1) For the state of the entity that is refreshed itself this is self-explanatory (simple select on the primary table, this is what already works). 2) For single-valued associations the proper query depends on whether the entity being refreshed represents the owning side or the inverse side of the association. If it is the inverse side, a simple query like this should do: ``` sql select addresses.id, ... from addresses where addresses.user_id=? ``` If it is the owning side, a join may be required: ``` sql select addresses.id, ... from addresses inner join users on addresses.id = users.address_id where users.id=? ``` 3) For one-to-many collections, a simple select on the target entity table, similar to the following should do: ``` sql select .... from phonenumbers ... where phonenumbers.user_id=? ``` For many-to-many collections a similar select that joins over the join table is required. An clever way for collections might be to not trigger this SQL immediately on refresh() but to simply mark the collection as uninitialized again so that the first access would trigger the reload, similar to a lazy-load. Note that the collection itself is refreshed, not the state of the entities contained therein. Also note that only associations need to be refreshed that were already initialized. If an associated collection is uninitialized, it does not need to be refreshed. If an associated single-valued proxy is uninitialized, it does not need to be refreshed.
admin added the Improvement label 2026-01-22 12:24:48 +01:00
admin closed this issue 2026-01-22 12:24:48 +01:00
Author
Owner

@doctrinebot commented on GitHub (Sep 25, 2009):

@doctrinebot commented on GitHub (Sep 25, 2009): - is required for [DDC-21: Already fetched associations should not be overriden by subsequent queries.](http://www.doctrine-project.org/jira/browse/DDC-21)
Author
Owner

@doctrinebot commented on GitHub (Oct 28, 2009):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Oct 28, 2009): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#28