-
-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
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
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
65 changes: 65 additions & 0 deletions
65
tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1152Test.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; | ||
|
||
use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs; | ||
use Doctrine\ODM\MongoDB\Events; | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; | ||
|
||
class GH1152Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest | ||
{ | ||
public function testParentAssociationsInPostLoad() | ||
{ | ||
$listener = new GH1152Listener(); | ||
$this->dm->getEventManager()->addEventListener(Events::postLoad, $listener); | ||
|
||
$parent = new GH1152Parent(); | ||
$parent->child = new GH1152Child(); | ||
|
||
$this->dm->persist($parent); | ||
$this->dm->flush(); | ||
|
||
$this->dm->clear(); | ||
|
||
$parent = $this->dm->find(GH1152Parent::CLASSNAME, $parent->id); | ||
$this->assertNotNull($parent); | ||
|
||
$this->assertNotNull($parent->child->parentAssociation); | ||
list($mapping, $parentAssociation, $fieldName) = $parent->child->parentAssociation; | ||
|
||
$this->assertSame($parent, $parentAssociation); | ||
} | ||
} | ||
|
||
/** @ODM\Document */ | ||
class GH1152Parent | ||
{ | ||
const CLASSNAME = __CLASS__; | ||
|
||
/** @ODM\Id */ | ||
public $id; | ||
|
||
/** @ODM\EmbedOne(targetDocument="GH1152Child") */ | ||
public $child; | ||
} | ||
|
||
/** @ODM\EmbeddedDocument */ | ||
class GH1152Child | ||
{ | ||
public $parentAssociation; | ||
} | ||
|
||
class GH1152Listener | ||
{ | ||
public function postLoad(LifecycleEventArgs $args) | ||
{ | ||
$dm = $args->getDocumentManager(); | ||
$document = $args->getDocument(); | ||
|
||
if (!$document instanceof GH1152Child) { | ||
return; | ||
} | ||
|
||
$document->parentAssociation = $dm->getUnitOfWork()->getParentAssociation($document); | ||
} | ||
} |