DDC-3285: \Doctrine\ORM\Event\PreUpdateEventArgs::getOldValue and ::getNewValue return wrong values for ManyToMany association #4066

Open
opened 2026-01-22 14:34:36 +01:00 by admin · 1 comment
Owner

Originally created by @doctrinebot on GitHub (Aug 29, 2014).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user reubent:

For most entities the $entityChangeSet[$field] contains an array of
[
0 => old_value
1 => new_value
]
however, for ManyToMany associations it contains a \Doctrine\ORM\PersistentCollection with the current (new) value of the association.

The getOldValue function relies on the other behaviour and simply returns $this->entityChangeSet[$field][0] which will be the first element in the PersistentCollection.

The getNewValue function does likewise but with the second element.

I'd be inclined to alter it to check if $entityChangeSet[$field] instanceof PersistentCollection and return the collection for newValue and throw some kind of Exception for oldValue but don't want to send a patch without checking how you guys would like this to react.

Originally created by @doctrinebot on GitHub (Aug 29, 2014). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user reubent: For most entities the $entityChangeSet[$field] contains an array of [ 0 => old_value 1 => new_value ] however, for ManyToMany associations it contains a \Doctrine\ORM\PersistentCollection with the current (new) value of the association. The getOldValue function relies on the other behaviour and simply returns $this->entityChangeSet[$field][0] which will be the first element in the PersistentCollection. The getNewValue function does likewise but with the second element. I'd be inclined to alter it to check if $entityChangeSet[$field] instanceof PersistentCollection and return the collection for newValue and throw some kind of Exception for oldValue but don't want to send a patch without checking how you guys would like this to react.
admin added the Bug label 2026-01-22 14:34:36 +01:00
Author
Owner

@doctrinebot commented on GitHub (Aug 29, 2014):

Comment created by reubent:

I guess this might be related to DDC-3033

@doctrinebot commented on GitHub (Aug 29, 2014): Comment created by reubent: I guess this might be related to [DDC-3033](http://www.doctrine-project.org/jira/browse/DDC-3033)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4066