【发布时间】:2015-06-26 20:53:28
【问题描述】:
我正在编写我的第一个 phalcon 应用程序,并且有一个问题是使用 Phalcon\Mvc\Model\Criteria 过滤查询。
最后我想要一个这样的查询
SELECT *
FROM table
WHERE
status = 'A' AND
(
title LIKE 'combining%' OR
title LIKE 'phalcon%' OR
(
title LIKE 'criteria%' AND
title LIKE '%phalcon'
)
)
对我来说,似乎没有办法在 phalcons 模型标准中使用括号。实现这一点的唯一方法是编写 phql。
我也许可以写这样的东西,而不是写一个完整的 phql,但这会变得同样复杂
<?php
$query = Table::query();
$query->where('status = :status:', array('status' => 'A'));
$query->andWhere('(
title LIKE :title1: OR
title LIKE :title2: OR (
title LIKE :title3: AND
title LIKE :title4:
)
)', array(
'title1' => 'combining%',
'title2' => 'phalcon%',
'title3' => 'criteria%',
'title4' => '%phalcon'
));
【问题讨论】:
-
你是什么版本的?
-
我在 ppa:phalcon/stable trusty