-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix composite key serialization #167
base: 1.5.x
Are you sure you want to change the base?
Conversation
This may be a (partial) fix for #135. |
Can you provide tests for that? |
@ddeboer, also, please rebase your commits. |
@ddeboer, I would like to be able to release this PR in 1.1 by tomorrow, do you think you would be able to care of it? |
6367b08
to
a804012
Compare
Rebased. Now working out how I can test this. Btw, the original issue description is not wholly accurate any more after using the solution from #135. |
29a15f5
to
b4707b6
Compare
@@ -22,7 +22,6 @@ | |||
use Doctrine\Common\DataFixtures\ProxyReferenceRepository; | |||
use Doctrine\Common\DataFixtures\Event\Listener\ORMReferenceListener; | |||
use Doctrine\ORM\Tools\SchemaTool; | |||
use Doctrine\ORM\Proxy\Proxy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was unused.
Adopt @cevou's solution from doctrine#135
b4707b6
to
ef54844
Compare
Done. |
Awesome! Thank you. |
// themselves have a composite primary key are unsupported. | ||
$proxyId = $this->getIdentifier($value, $uow); | ||
$keys = array_keys($proxyId); | ||
$values[$key] = $proxyId[$keys[0]]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if I’m misunderstanding something, but wouldn’t this create ID collisions? Why not use implode('|', $proxyId)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most cases, where the related entity has a single (not composite) primary key, count($proxyId) === 1
.
Imploding the keys is an option, but unfortunately won’t help much. When the references are unserialized, references are retrieved from the entity manager. However, Doctrine does not support something like:
$roleRef = $em->getReference(self::TEST_ENTITY_USER_ROLE, [
'role' => 1,
'user' => [ // Doctrine doesn’t like this nested composite key
'id' => 1,
'code' => '007'
]
]);
After having carefully considered this PR and asked other guys on the Doctrine team, we won’t be accepting it as is. Before releasing support for composite keys, it will need to support all cases and/or have tests for all those. I will reschedule this PR for 1.2 and will come back when I have a better understanding. Thanks again. |
I too prefer full support for nested composite keys, but as this requires changes in Doctrine itself I think starting simple, with support for unnested primary keys, is the way to go. Why does the solution have to tackle all cases at once? Why not work on a solution iteratively? |
66891de
to
0db2c74
Compare
0db2c74
to
04c3b50
Compare
Currently, calling
unserialize()
with some data previously returned fromserialize()
produces:This is caused by
serialize()
incorrectly serializing entities with primary keys (on doctrine/orm 2.4.):This seems to be caused by the identifier lookup for
$simpleReferences
not working properly. For each object constituting the composite key, it returns the object itself instead of its id. E.g.:By adding a
getReference()
the identifier lookup works correctly. It now looks at$this->identities
first, which holds the correct composite identities. Of course, the extra call does have a slight performance impact: