【问题标题】:Phalcon mongodb cannot updatePhalcon mongodb 无法更新
【发布时间】:2018-10-11 22:43:43
【问题描述】:

我无法使用 Incubator 3.3 中的 Phalcon MongoCollection 更新文档 save() 后我没有收到任何错误,但数据没有更新。

我的代码是:

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

我也尝试过孵化器 3.4 和 3.2

【问题讨论】:

    标签: phalcon mongo-collection


    【解决方案1】:

    我不知道为什么,但在调用单例之后:

    MyModel::findById($id)

    ...我在模型构造函数中定义的源集合从 'myCustomCollection' 更改为 'my_model'

    我通过在 app/vendor/phalcon/incubator/Library/Phalcon/Mvc/MongoCollection.php 的 _getResultSet 方法中添加一些临时代码来修复它(第 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;
    
        }
    

    【讨论】:

      猜你喜欢
      • 2014-06-01
      • 1970-01-01
      • 2020-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-16
      • 2015-02-21
      相关资源
      最近更新 更多