Created
February 28, 2017 10:16
-
-
Save alcaeus/af289aabfe38635bc5ee6154c58302f6 to your computer and use it in GitHub Desktop.
Relationship from child document to parent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs; | |
/** | |
* @ODM\EmbeddedDocument | |
* @ODM\HasLifecycleCallbacks | |
*/ | |
class EmbeddedDocument | |
{ | |
private $parent; | |
public function __construct(Parent $parent) | |
{ | |
$this->parent = $parent; | |
} | |
/** @ODM\PostLoad */ | |
public function postLoad(LifecycleEventArgs $args) | |
{ | |
$uow = $args->getDocumentManager()->getUnitOfWork(); | |
[, $this->parent] = $args->getDocumentManager()->getUnitOfWork()->getParentAssociation($this); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** @ODM\Document **/ | |
class Parent | |
{ | |
/** @ODM\EmbedOne(...) */ | |
private $embedded; | |
public function __construct() | |
{ | |
$this->embedded = new Embedded($this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment