Phalcon 中是否可以 运行 findFirst() with IN 子句?

Is it possible to run findFirst() with IN clause in Phalcon?

我想在 findFirst 中使用 IN 子句,但它似乎不起作用?

预期代码或类似代码:

$item = Item::findFirst([
    'conditions' => 'categories IN :cats: AND released < :now:',
    'order'      => 'id ASC',
    'bind'       => [
        'cats'     => $this->categories,
        'released' => time()
    ],
]);

我尝试使用 bindTypes 但没有这样的 "list" 或 "array" 类型(另外,这会比预期的更冗长)...

我知道我可以通过查询生成器来做到这一点,但我希望让它更加地道:

$item = Item::query()
    ->inWhere('categories', $this->categories)
    ->andWhere('released < :now:', ['now' => time()])
    ->orderBy('id ASC')
    ->limit(1)
    ->execute()
    ->getFirst();

您可以像这样绑定数组和 IN 子句:

$result = ModelName::findFirst([
    'conditions' => 'id in ({cats:array})',
    'bind' => array('cats' => [3, 5, 8])
]);

请注意,上面的示例将获取 ID 为 3 的第一条记录。但是,如果您使用 find(),您将获取 ID 为 3、5 和 8 的项目。

docs(在本节底部)中有更多示例。