Cakephp 2在条件数组中使用EXISTS

时间:2016-08-17 19:22:17

标签: cakephp

我正在使用cakePHP 2.5.2,我需要在条件数组中使用exists子句。

这就是我想要的:

$paginate['conditions'][] = Array('exists ("SELECT 1 FROM jobs j JOIN company c ON c.id = j.company_id")');

我收到“标识符太长的消息”并且没有生成结果。

生成的查询是:

AND exists ("SELECT 1 FROM jobs j JOIN company c ON c.id = j.company_id")

如何在conditions数组中使用exists?

1 个答案:

答案 0 :(得分:1)

如果您正在使用MySql EXISTS功能,那么问题在于您的引号。尝试更改:

$paginate['conditions'][] = Array(
    'exists ("SELECT 1 FROM jobs j JOIN company c ON c.id = j.company_id")'
);

$paginate['conditions'][] = Array(
    "exists (SELECT 1 FROM jobs j JOIN company c ON c.id = j.company_id)"
);