phalconmongo-collection

Phalcon mongodb cannot update


I can't update a document with Phalcon MongoCollection from Incubator 3.3 I don't get any error after save() but data are not updated.

My code is:

$category = CategoryModel::findById($id);
$category->title = 'uno';
$category->save();

I have also tried with incubator 3.4 and 3.2


Solution

  • I don't know why but after calling the singleton:

    MyModel::findById($id)

    ...the source collection I defined on the model constructor changes from 'myCustomCollection' to 'my_model'

    I fixed it by adding some temporary code inside the _getResultSet method from app/vendor/phalcon/incubator/Library/Phalcon/Mvc/MongoCollection.php (Line 310)

    $cursor->setTypeMap(['root' => get_class($base), 'document' => 'array']);
    
        if (true === $unique) {
    
            /**
             * Looking for only the first result.
             */
            $output = current($cursor->toArray());
    
            $output->setSource($base->getSource());
    
            return $output;
    
        }