diff --git a/tests/Doctrine/Tests/Models/CMS/CmsEmail.php b/tests/Doctrine/Tests/Models/CMS/CmsEmail.php index c79c30036..0faf4b876 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsEmail.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsEmail.php @@ -22,7 +22,7 @@ class CmsEmail public $email; /** - * @OneToOne(targetEntity="CmsUser", mappedBy="email") + * @OneToOne(targetEntity="CmsUser", mappedBy="email", cascade={"persist"}) */ public $user; diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index 7bdb84653..a61595af6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -9,6 +9,7 @@ use Doctrine\ORM\ORMInvalidArgumentException; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Proxy\Proxy; use Doctrine\ORM\Query; +use Doctrine\Tests\Models\CMS\CmsEmail; use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsArticle; @@ -801,6 +802,50 @@ class BasicFunctionalTest extends OrmFunctionalTestCase $this->_em->flush(); } + /** + * @group DDC-2922 + */ + public function testNewAssociatedEntityWorksWithJustOnePath() + { + + /** + * First we persist and flush an e-mail with no user. This seems + * Save an un-owned email with no user. This seems to + * matter for reproducing the bug + */ + $mail = new CmsEmail(); + $mail->email = "nobody@example.com"; + $mail->user = null; + + $this->_em->persist($mail); + $this->_em->flush(); + + $user = new CmsUser(); + $user->username = "beberlei"; + $user->name = "Benjamin E."; + $user->status = 'active'; + + $mail->user = $user; + + /** + * Note that we have NOT directly persisted the CmsUser, and CmsAddress + * does NOT have cascade-persist. + * + * However, CmsEmail *does* have a cascade-persist, which ought to + * allow us to save the CmsUser anyway through that connection. + */ + $address = new CmsAddress(); + $address->city = "Bonn"; + $address->zip = "12354"; + $address->country = "Germany"; + $address->street = "somestreet"; + $address->user = $user; + + $this->_em->persist($address); + $this->_em->flush(); + + } + public function testOneToOneOrphanRemoval() { $user = new CmsUser();