Skip to content

Commit

Permalink
Merge pull request #266 from doctrine/fix-referrer-cascade-update-ref…
Browse files Browse the repository at this point in the history
…erence

fix referrer cascade to really update referencing document
  • Loading branch information
dbu committed Mar 14, 2013
2 parents 262defc + f8c335a commit b7f40b9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ protected function validateAndCompleteFieldMapping($mapping, ClassMetadata $inhe
throw new MappingException("fieldName must be of type string in '{$this->name}'.");
}

if (!isset($mapping['name'])) {
if (!isset($mapping['name']) || empty($mapping['name'])) {
$mapping['name'] = $mapping['fieldName'];
}

Expand Down
7 changes: 6 additions & 1 deletion lib/Doctrine/ODM/PHPCR/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,12 @@ public function computeChangeSet(ClassMetadata $class, $document)
if (isset($class->mappings[$fieldName])) {
if ($this->originalData[$oid][$fieldName] !== $fieldValue) {
continue;
} elseif ($fieldValue instanceof ReferenceManyCollection && $fieldValue->changed()) {
}
if (($fieldValue instanceof ReferenceManyCollection
|| $fieldValue instanceof ReferrersCollection
)
&& $fieldValue->changed()
) {
continue;
}
}
Expand Down
12 changes: 6 additions & 6 deletions tests/Doctrine/Tests/ODM/PHPCR/Functional/CascadePersistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ public function testCascadeManagedDocumentReferrerDuringFlush()
$user = $this->dm->find('Doctrine\Tests\Models\CMS\CmsUser', '/functional/dbu');
$this->assertNotNull($user);
$this->assertTrue(1 <= count($user->articlesReferrers));
$article = $user->articlesReferrers->first();
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $article);
$this->assertEquals($article->id, $article->id);
$savedArticle = $user->articlesReferrers->first();
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsArticle', $savedArticle);
$this->assertEquals($article->id, $savedArticle->id);

$article->user = null;
$savedArticle->user = null;
$this->dm->flush();
$this->dm->clear();

$article = $user->articlesReferrers->first();
$this->assertNull($article->user);
$removedArticle = $user->articlesReferrers->first();
$this->assertNull($removedArticle->user);
}
}
3 changes: 3 additions & 0 deletions tests/Doctrine/Tests/ODM/PHPCR/Functional/ReferrerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;

/**
* These tests test if referrers are correctly read. For cascading
* referrers, see CascadePersistTest
*
* @group functional
*/
class ReferrerTest extends \Doctrine\Tests\ODM\PHPCR\PHPCRFunctionalTestCase
Expand Down

0 comments on commit b7f40b9

Please sign in to comment.