Skip to content

Commit

Permalink
[MODM-61] Fixing issue with storing instances of MongoGridFSFile
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage committed Aug 30, 2010
1 parent c12c923 commit e8945bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Doctrine/ODM/MongoDB/UnitOfWork.php
Expand Up @@ -350,6 +350,11 @@ public function getDocumentActualData($document)

$origValue = $class->getFieldValue($document, $mapping['fieldName']);

// Skip MongoGridFSFile instances as we never store these objects
if ($origValue instanceof \MongoGridFSFile) {
continue;
}

if (($class->isCollectionValuedReference($name) || $class->isCollectionValuedEmbed($name))
&& $origValue !== null && ! ($origValue instanceof PersistentCollection)) {
// If $actualData[$name] is not a Collection then use an ArrayCollection.
Expand Down Expand Up @@ -436,7 +441,6 @@ public function computeChangeSet($parentDocument, Mapping\ClassMetadata $class,

$oid = spl_object_hash($document);
$actualData = $this->getDocumentActualData($document);

if ( ! isset($this->originalDocumentData[$oid])) {
// Document is either NEW or MANAGED but not yet fully persisted (only has an id).
// These result in an INSERT.
Expand Down
14 changes: 14 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/FilesTest.php
Expand Up @@ -9,6 +9,20 @@

class FilesTest extends \Doctrine\ODM\MongoDB\Tests\BaseTest
{
public function testFlushTwice()
{
$image = new File();
$image->setName('Test');
$image->setFile(__DIR__ . '/file.txt');
$this->dm->persist($image);
$this->dm->flush();
$this->dm->flush();

$test = $this->dm->getDocumentCollection('Documents\File')->findOne();
$this->assertFalse(isset($test['file']->file['file']));

}

public function testFiles()
{
$image = new File();
Expand Down

0 comments on commit e8945bc

Please sign in to comment.