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
This is a relevant code from PersistenceBuilder::prepareInsertData
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE) {
if ($mapping['isInverseSide']) {
continue;
}
$oid = spl_object_hash($new);
if ($this->isScheduledForInsert($new)) {
// The associated document $new is not yet persisted, so we must// set $new = null, in order to insert a null value and schedule an// extra update on the UnitOfWork.$this->uow->scheduleExtraUpdate($document, array(
$mapping['fieldName'] => array(null, $new)
));
} else {
$value = $this->prepareReferencedDocumentValue($mapping, $new);
}
// @EmbedOne
}
If I change it to:
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE) {
if ($mapping['isInverseSide']) {
continue;
}
$oid = spl_object_hash($new);
if ($this->isScheduledForInsert($new)) {
// The associated document $new is not yet persisted, so we must// set $new = null, in order to insert a null value and schedule an// extra update on the UnitOfWork.$this->uow->scheduleExtraUpdate($document, array(
$mapping['fieldName'] => array(null, $new)
));
} else {
$value = $this->prepareReferencedDocumentValue($mapping, $new);
}
// Store a discriminator value if the embedded document is not mapped explicitly to a targetDocumentif (isset($mapping['discriminatorField'])) {
$insertData[$mapping['discriminatorField']] = $this->getDiscriminatorValue($mapping, $new);
}
// @EmbedOne
}
and add getDiscriminatorValue private function:
/** * Returns discriminator value for a document. * * @param array $mapping * @param object $document * @return string * * @throws RuntimeException If discriminator map doesn't contain an entry for document */privatefunctiongetDiscriminatorValue(array$mapping, $document)
{
$refClassName = get_class($document);
if (isset($mapping['discriminatorMap'])) {
$key = array_search($refClassName, $mapping['discriminatorMap']);
if (! $key) {
thrownew \RuntimeException(sprintf(
'Discriminator map does not contain an entry for %s',
$refClassName
));
}
return$key;
}
return$refClassName;
}
What do you guys think? Is there a better way to solve this problem? Or am I just missing something?
The text was updated successfully, but these errors were encountered:
So ReferenceOne with discriminator map/type doesn't seem to be working. It's not saving the type. This is what my mapping file looks like:
And all I have in the DB is:
model_type is not set.
This is a relevant code from PersistenceBuilder::prepareInsertData
If I change it to:
and add getDiscriminatorValue private function:
What do you guys think? Is there a better way to solve this problem? Or am I just missing something?
The text was updated successfully, but these errors were encountered: