I have document with ReferenceOne:
/** @MongoDB\Document */
class Petition
{
// ...
/** @MongoDB\ReferenceOne(targetDocument="AcmeBundle\Document\Result",
cascade={"persist"}) */
protected $result;
public function setResult($result)
{
$this->result = $result;
return $this;
}
// ...
}
And documents referenced:
/** @MongoDB\Document */
class Result
{
// ...
/** @MongoDB\Id(strategy="NONE") */
protected $id;
// ...
}
Somewhere in my code:
$r = $this->mongo->getManager()->find('AcmeBundle:Result', 0);
$dm = $this->mongo->getManager();
$pet = new \AcmeBundle\Document\Petition($res->data);
$pet->setResult($r);
$dm->persist($pet);
$dm->flush();
Mongo database and collection has a document 'Result' with id = 0 (
{'_id':0, 'title':''})
I get RuntimeException, when try persist 'Petition' document:
[RuntimeException]
Cannot create a DBRef for class AcmeBundle\Document\Result without an
identifier. Have you forgotten to persist/merge the document first?
And StackTrace:
Exception trace:
() at /acme/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/
DocumentManager.php:679
Doctrine\ODM\MongoDB\DocumentManager->createDBRef() at /acme/vendor/
doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.
php:320
Doctrine\ODM\MongoDB\Persisters\PersistenceBuilder->
prepareReferencedDocumentValue() at /acme/vendor/doctrine/mongodb-odm/lib/
Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php:286
Doctrine\ODM\MongoDB\Persisters\PersistenceBuilder->prepareUpsertData() at
/acme/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/
DocumentPersister.php:280
Doctrine\ODM\MongoDB\Persisters\DocumentPersister->executeUpserts() at /
acme/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php:
1130
Doctrine\ODM\MongoDB\UnitOfWork->executeUpserts() at /acme/vendor/doctrine/
mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php:416
Doctrine\ODM\MongoDB\UnitOfWork->commit() at /acme/vendor/doctrine/mongodb-
odm/lib/Doctrine/ODM/MongoDB/DocumentManager.php:528
Doctrine\ODM\MongoDB\DocumentManager->flush() at /acme/src/AcmeBundle/
Services/Core.php:116
AcmeBundle\Services\Core->updatePetition() at /acme/src/AcmeBundle/Command/
PetitionCommand.php:27
AcmeBundle\Command\PetitionCommand->execute() at /acme/vendor/symfony/
symfony/src/Symfony/Component/Console/Command/Command.php:259
Symfony\Component\Console\Command\Command->run() at /acme/vendor/symfony/
symfony/src/Symfony/Component/Console/Application.php:886
Symfony\Component\Console\Application->doRunCommand() at /acme/vendor/
symfony/symfony/src/Symfony/Component/Console/Application.php:195
Symfony\Component\Console\Application->doRun() at /acme/vendor/symfony/
symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /acme/vendor
/symfony/symfony/src/Symfony/Component/Console/Application.php:126
Symfony\Component\Console\Application->run() at /acme/app/console:27
Probably should checking to change the condition to *isset*()?
diff --git a/lib/Doctrine/ODM/MongoDB/DocumentManager.php
b/lib/Doctrine/ODM/MongoDB/DocumentManager.php
old mode 100644
new mode 100755
index cd0de83..eae4baa
--- a/lib/Doctrine/ODM/MongoDB/DocumentManager.php
+++ b/lib/Doctrine/ODM/MongoDB/DocumentManager.php
@@ -675,7 +675,7 @@
$class = $this->getClassMetadata(get_class($document));
$id = $this->unitOfWork->getDocumentIdentifier($document);
- if ( ! $id) {
+ if ( !isset($id) ) {
throw new \RuntimeException(
sprintf('Cannot create a DBRef for class %s without an
identifier. Have you forgotten to persist/merge the document first?',
$class->name)
);
Or I misunderstood concept of Mongo?
Thanks for doctrine :)
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.