重写dataSource::read()并使用item()会得到不正确的结果


Overriding dataSource::read() and using item() gives me incorrect results

我正试图通过以下创建数据源来覆盖lithium'data'source'Http::read()。这是我在"如何在锂中提交cURL的POST"中遇到问题的结果。

我现在有这样的东西:

<?php
namespace li3_tr42Auth'extensions'adapter'data'source'http;
class TR42 extends 'lithium'data'source'Http {
    protected $_classes = [
        // unlike in the "Creating Data Sources" doc, I had to add the 'schema' key
        // or I get an error when 'Libraries' tries to instantiate it.
        'schema'  => 'lithium'data'DocumentSchema',
        'service' => 'lithium'net'http'Service',
        'entity'  => 'lithium'data'entity'Document',
        'set'     => 'lithium'data'collection'DocumentSet'
    ];
    public function read($query, array $options = []) {
        $params = $query->export($this, ['keys' => ['source', 'conditions']]);
        $source = Inflector::camelize($params['source']);
        $model = Libraries::locate('models', $source);
        .
        .
        .
        $decoded = $this->decode($response);
        /** at this point, $decoded contains an associative array like:
         * Array(
         *     [id] => 42,
         *     [name] => Housni,
         *     [status] => 1,
         *     [country] => Colombo, Sri Lanka
         * )
         */
        return $model::create($decoded, ['exists' => true]);
    }
}
?>

如果我不使用item(),任何查找器都会按原样返回数组。如果我确实使用了item(),那么在这种情况下,我只得到数组的第一个值,即42

知道我在这里做错了什么吗?

更新事实证明,只有find('first')会导致上述问题。使用find('all')返回一个对象,正如预期的那样。不太确定如何解决这个问题。

更新#2我用新的返回代码更新了上面的read()代码。如果我在从read()返回之前显示结果,我会看到一个合适的Document对象。find()方法中似乎发生了一些事情。顺便说一句,我没有为这个模型运行任何过滤器。知道我如何调试这个吗?

item()已不存在
你只需要用YourModel::create($decoded, ['exists' => true]); 替换这条线路

请在手动回购中打开一个问题以更新这部分文档;-)