-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Custom type ignored by identity generator #5684
Comments
I would like to add, that even if you try to create your own generator that will convert the value, well too bad, because doctrine is hardcoded to add autoincrement only when generated value strategy is identity. If you try to roll your own, its impossible to have autoincrement on your columns. |
I encountered the same problem today. A small debugging session pointed me to https://github.com/doctrine/doctrine2/blob/2b476708311b6003881a0cb944ca8c1bf996d58a/lib/Doctrine/ORM/UnitOfWork.php#L1016 where the value of the id generator gets directly assigned. I made a few quick changes directly below the linked line and it seems to work well. The changes are: $platform = $this->em->getConnection()->getDatabasePlatform();
$idType = $this->em->getClassMetadata(get_class($entity))->fieldMappings[$idField]['type'];
$mappedId = Types\Type::getType($idType)->convertToPHPValue($id, $platform);
$class->reflFields[$idField]->setValue($entity, $mappedId); The I'm not sure if this has any relevant performance (or other) issues. If someone could confirm that these changes are reasonable, I would be happy to submit a pull request within the next days. Just let me know. 😉 |
This was handled in #6152 |
I have a custom type which extends the
IntegerType
. It encodes the integer on the way out of the database, and decodes it on the way in with the use ofconvertToPHPValue
/convertToDatabaseValue
. I tried using it like so:The problem with this implementation is that the generated value returned from the database after a
persist
/flush
operation is the integer stored in the database; not the value as it would be had it passed through theconvertToPHPValue
method of my custom type.The text was updated successfully, but these errors were encountered: