Skip to content

Instantly share code, notes, and snippets.

@alcaeus
Created October 1, 2019 09:17
Show Gist options
  • Save alcaeus/8f91cc6ad367ed842a88ff7c5bfee3ab to your computer and use it in GitHub Desktop.
Save alcaeus/8f91cc6ad367ed842a88ff7c5bfee3ab to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\ODM\MongoDB\Tests\BaseTest;
class GH2039Test extends BaseTest
{
public function testReferencedDocumentInsideEmbeddedDocument()
{
$document = new GH2039Document('foo');
$this->dm->persist($document);
$this->dm->flush();
$this->dm->clear();
$builder = $this->dm->createAggregationBuilder(GH2039Document::class);
$builder
->hydrate(GH2039Result::class)
->addFields()
->field('document')
->expression('$$ROOT')
;
$result = $builder->execute()->toArray();
$this->assertCount(1, $result);
$this->assertInstanceOf(GH2039Result::class, $result[0]);
$this->assertEquals($document, $result[0]->document);
}
}
/** @ODM\Document */
class GH2039Document
{
/** @ODM\Id */
protected $id;
/** @ODM\Field(type="string") */
public $name;
public function __construct($name)
{
$this->name = $name;
}
}
/** @ODM\QueryResultDocument() */
class GH2039Result
{
/** @ODM\EmbedOne(targetDocument=GH2039Document::class) */
public $document;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment