You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
We encountered difficulties with class inheritance when using an assigned ID strategy. This is because, when field mappings are copied from a parent class to a child, the name of the ID field is copied, but the ID generator strategy is not.
Steps to reproduce:
Create a parent class and a child class that inherits from it. Put the ID field in the parent class.
Define the mapping with an assigned ID strategy.
Instantiate a new child object, assign an ID and try to persist it to the database.
The exception "Detached document passed to persist()" is thrown from line 349 of UnitOfWork. The default ID generator strategy is "UUID", so UnitOfWork incorrectly assumes that the document is detached because the ID field is populated.
We have also discovered that the isVersioned and versionField properties are not copied from parent to child.
Our workaround is to add lines to Doctrine\ODM\CouchDB\Mapping\ClassMetaDataFactory::addFieldMapping() as follows:
private function addFieldMapping(ClassMetadataInterface $class, ClassMetadataInterface $parent)
{
foreach ($parent->reflFields as $name => $field) {
$class->reflFields[$name] = $field;
}
foreach ($parent->fieldMappings as $name => $field) {
$class->fieldMappings[$name] = $field;
}
foreach ($parent->jsonNames as $name => $field) {
$class->jsonNames[$name] = $field;
}
if ($parent->identifier) {
$class->setIdentifier($parent->identifier);
$class->idGenerator = $parent->idGenerator; // <----- added line
}
// Added lines from here...
if ($parent->isVersioned) {
$class->isVersioned = $parent->isVersioned;
$class->versionField = $parent->versionField;
}
// ... to here
}
So far this change hasn't broken anything else for us.
The text was updated successfully, but these errors were encountered:
Hi,
We encountered difficulties with class inheritance when using an assigned ID strategy. This is because, when field mappings are copied from a parent class to a child, the name of the ID field is copied, but the ID generator strategy is not.
Steps to reproduce:
The exception "Detached document passed to persist()" is thrown from line 349 of UnitOfWork. The default ID generator strategy is "UUID", so UnitOfWork incorrectly assumes that the document is detached because the ID field is populated.
We have also discovered that the isVersioned and versionField properties are not copied from parent to child.
Our workaround is to add lines to
Doctrine\ODM\CouchDB\Mapping\ClassMetaDataFactory::addFieldMapping()
as follows:So far this change hasn't broken anything else for us.
The text was updated successfully, but these errors were encountered: