Phalcon 查找列参数 returns 行而不是模型

Phalcon find with columns parameter returns rows instead models

当我使用 Model::find() 时,响应是模型的结果集,但是当我添加 columns 参数来限制返回的列时,响应是行的结果集。

示例:

// Resultset of Models
$users = \Models\Users\Users::find();

// Resultset of Rows
$users = \Models\Users\Users::find([
        'columns' => 'id, email'
]);

这让我无法调用模型方法。有没有办法在 ::find() 方法中使用列限制的模型结果集?我不确定,但这似乎是个错误,因为 Phalcon 文档说:

While findFirst() returns directly an instance of the called class (when there is data to be returned), the find() method returns a Phalcon\Mvc\Model\Resultset\Simple.

并且在使用columns参数时没有关于此规则的例外情况。

我还注意到 ::find() 的其他参数,如 conditionorderbind 等工作正常(返回模型)。

Phalcon 1.3.4

这不是错误,而是预期的行为。 the docs 中的信息向下滚动到参数 table 并阅读 .

的描述

如果您需要使用模型方法或关系,则不应指定列。但是如果你追求更好的性能并且不需要模型关系,你应该使用 Query Builder.

find() 的其余参数,如条件、顺序 e.t.c。不会影响您使用模型方法的能力。

findFirst() 方法也像 find() 方法一样工作。此处示例:

未指定列:

News::findFirst(3);

// Output
Models\News Object
(
...

指定列时

News::findFirst([
    'columns' => 'id, created_at'
]);

// Output
Phalcon\Mvc\Model\Row Object
(
    [id] => 1
    [created_at] => 2016-02-02
)