DDC-773: When a partial reference exists, ::find() return partial objects #953

Closed
opened 2026-01-22 12:57:08 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Aug 27, 2010).

Jira issue originally created by user arnaud-lb:

In the following example, the object returned by EntityManager::find() is a partial object (the partial reference) :

$a = $em->getPartialReference('\Foo', 1);
$b = $em->find(1);

var_dump($a->getSomeField()); // NULL
var_dump($b->getSomeField()); // NULL

var_dump($a === $b); // TRUE, $b is $a

Originally created by @doctrinebot on GitHub (Aug 27, 2010). Jira issue originally created by user arnaud-lb: In the following example, the object returned by EntityManager::find() is a partial object (the partial reference) : ``` $a = $em->getPartialReference('\Foo', 1); $b = $em->find(1); var_dump($a->getSomeField()); // NULL var_dump($b->getSomeField()); // NULL var_dump($a === $b); // TRUE, $b is $a ```
admin added the Bug label 2026-01-22 12:57:08 +01:00
admin closed this issue 2026-01-22 12:57:09 +01:00
Author
Owner

@doctrinebot commented on GitHub (Aug 27, 2010):

Comment created by romanb:

This is not a bug. Partial objects are managed just like other ones.

@doctrinebot commented on GitHub (Aug 27, 2010): Comment created by romanb: This is not a bug. Partial objects are managed just like other ones.
Author
Owner

@doctrinebot commented on GitHub (Aug 27, 2010):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Aug 27, 2010): Issue was closed with resolution "Invalid"
Author
Owner

@doctrinebot commented on GitHub (Aug 27, 2010):

Comment created by arnaud-lb:

I would not expect EntityManager::find() to return a partial object. Maybe find() should return a new, non-partial object; or update the existing partial.

The current behavior will surely be the cause of non-obvious bugs.

@doctrinebot commented on GitHub (Aug 27, 2010): Comment created by arnaud-lb: I would not expect EntityManager::find() to return a partial object. Maybe find() should return a new, non-partial object; or update the existing partial. The current behavior will surely be the cause of non-obvious bugs.
Author
Owner

@doctrinebot commented on GitHub (Aug 27, 2010):

Comment created by @beberlei:

Maybe we should document this behaviour more clearly in the docblock and add a warning.

This is the desired behaviour of getPartialReference().

@doctrinebot commented on GitHub (Aug 27, 2010): Comment created by @beberlei: Maybe we should document this behaviour more clearly in the docblock and add a warning. This is the desired behaviour of getPartialReference().
Author
Owner

@doctrinebot commented on GitHub (Aug 27, 2010):

Comment created by romanb:

@"The current behavior will surely be the cause of non-obvious bugs."

Yes, that is absolutely right but that is the risk of using partial objects. You can run into a lot of different issues with them. That's why you should only use them when you really know what you're doing and when you want to take the risk, ideally always making the scope of partial objects as small as possible.

For example, when you ->detach($partial) as soon as you're done with it, you can avoid this problem.

Example:

$partial = $em->getPartialReference(...);
// update some association or whatever you want to do with the partial reference
// and flush, if necessary.
$em->detach($partial); // throw $partial out of the persistence context

// ... somewhere else / later ...

$e = $em->find(...);

// no problems with $e
@doctrinebot commented on GitHub (Aug 27, 2010): Comment created by romanb: @"The current behavior will surely be the cause of non-obvious bugs." Yes, that is absolutely right but that is the risk of using partial objects. You can run into a lot of different issues with them. That's why you should only use them when you really know what you're doing and when you want to take the risk, ideally always making the scope of partial objects as small as possible. For example, when you ->detach($partial) as soon as you're done with it, you can avoid this problem. Example: ``` $partial = $em->getPartialReference(...); // update some association or whatever you want to do with the partial reference // and flush, if necessary. $em->detach($partial); // throw $partial out of the persistence context // ... somewhere else / later ... $e = $em->find(...); // no problems with $e ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#953