We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Oracle数据库下模型的sum和count方法无法使用。

sum方法报错:Column 'SUMATORY' doesn't make part of the column map

count方法报错:Column 'ROWCOUNT' doesn't make part of the column map

请问如何处理?

Are you using Phalcon 2.0.6?

edited Aug '15

我用的是Phalcon 2.0.3。

Phalcon 2.0.6可以吗?

There is an option in 2.0.6 to avoid these kind of exceptions:

\Phalcon\Mvc\Model::setup(["ignoreUnknownColumns" => true]);


5.4k
Accepted
answer
edited Aug '15

升级到Phalcon 2.0.6后,新的问题又来了。

User::findFirst() 找不出结果,返回boolean false,并且测试发现,sum和count依然没有用。

Users::count() 得到的结果是 null,sum方法得到的结果也是null

Phalcon 2.0.3版本下findFirst是可以用的。

另外,ignoreUnknownColumns有作用,没有再出现上述错误:Column 'xxx' doesn't make part of the column map

不小心点到了“Accepted answer”,如何取消? 问题还是没有解决。

重写上述方法:

public static function count($parameters = NULL) { if(DB_TYPE == 'oci') { $classname = get_called_class(); $instance = new $classname; $tablename = $instance->getSource(); $sql = "SELECT COUNT(*) AS ROWCOUNT FROM $tablename"; is_array($parameters) || $parameters = array($parameters); if($parameters[0]) { $sql .= " WHERE {$parameters[0]}"; } $result = $instance->getReadConnection()->fetchOne($sql, \Phalcon\Db::FETCH_ASSOC, $parameters['bind']); return (int)$result['ROWCOUNT']; } else { return parent::count($parameters); } }