Doctrine MongoDB ODM
  1. Doctrine MongoDB ODM
  2. MODM-42

PersistentCollection fails when working with MongoGridFs

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0.0BETA1
    • Component/s: Collections
    • Labels:
      None

      Description

      Getting following error when trying to use MongoGridFs files with referenceMany:

      Argument 2 passed to Doctrine\ODM\MongoDB\UnitOfWork::getOrCreateDocument() must be an array, object given, called in 
      D:\Work\www\syter2.localhost.dev\library\Doctrine\ODM\MongoDB\PersistentCollection.php on line 110 and defined
      D:\Work\www\syter2.localhost.dev\library\Doctrine\ODM\MongoDB\UnitOfWork.php:1719
      

      As far as I understand queries against MongoGridFS collection return instances of MongoGridFSFile, while PersistentCollection only expects arrays (as with regular collections)

      I think Issue appeared after latest updates from git. Because I didn't experience it with ALPHA1 (didn't test with ALPHA2)

        Activity

        Hide
        Jonathan H. Wage added a comment -

        I'll check it out, if you can provide a test that'd be helpful.

        Show
        Jonathan H. Wage added a comment - I'll check it out, if you can provide a test that'd be helpful.
        Hide
        Vladimir Razuvaev added a comment -

        Here is a test case:

        /** @Document(db="tests", collection="tests") */
        class a
        {
            /** @Id */
            protected $id;
        
            /** @ReferenceMany(targetDocument="file") */
            protected $files = array();
        
            function __construct($files) {$this->files = $files;}
        
            function getFiles() {return $this->files;}
        }
        
        /** @Document(db="tests", collection="files") */
        class file
        {
            /** @Id */
            protected $id;
        
            /** @File */
            protected $file;
        
            function __construct($path) {$this->file = $path;}
        
            function getMongoFile() {return $this->file;}
        }
        
        $f = new file(__DIR__ . '/test.txt');
        $a = new a(array($f));
        
        $dm->persist($f);
        $dm->persist($a);
        $dm->flush();
        
        $dm->getUnitOfWork()->clear();
        
        $a = $dm->findOne('a', array());
        foreach($a->getFiles() as $file) {
            $file->getMongoFile(); // produces catchable fatal error
        }
        
        Show
        Vladimir Razuvaev added a comment - Here is a test case: /** @Document(db= "tests" , collection= "tests" ) */ class a { /** @Id */ protected $id; /** @ReferenceMany(targetDocument= "file" ) */ protected $files = array(); function __construct($files) {$ this ->files = $files;} function getFiles() { return $ this ->files;} } /** @Document(db= "tests" , collection= "files" ) */ class file { /** @Id */ protected $id; /** @File */ protected $file; function __construct($path) {$ this ->file = $path;} function getMongoFile() { return $ this ->file;} } $f = new file(__DIR__ . '/test.txt'); $a = new a(array($f)); $dm->persist($f); $dm->persist($a); $dm->flush(); $dm->getUnitOfWork()->clear(); $a = $dm->findOne('a', array()); foreach($a->getFiles() as $file) { $file->getMongoFile(); // produces catchable fatal error }
        Show
        Jonathan H. Wage added a comment - Fixed in http://github.com/doctrine/mongodb-odm/commit/964ce247841d11af8ab28cfbde36f6cc09b0d366

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Vladimir Razuvaev
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: