500 Ошибка приложения

Firebird prepare query error:Dynamic SQL Error SQL error code = -104 Invalid expression in the ORDER BY clause (not contained in either an aggregate function or the GROUP BY clause) select "ORGUNITS"."SYS_GUID",count(KGSEQ.SYS_GUID) as "COUNT" from "ORGUNITS" inner join "KGSEQ" as "KGSEQ" on ("KGSEQ"."GOVERMENTFK"="ORGUNITS"."SYS_GUID") where mod(coalesce("ORGUNITS"."SYS_STATE",0),2)=0 and ("ORGUNITS"."SYS_PARENTGUID" is null) and mod(coalesce("KGSEQ"."SYS_STATE",0),2)=0 group by "ORGUNITS"."SYS_GUID" order by "ID"

В файле: /var/www/x1db-php/library/X1/Db/Adapter/Firebird.php:320

Трассировка:

#0 /var/www/x1db-php/library/X1/Db/Statement.php(57): X1\Db\Adapter\Firebird->prepare('select  "ORGUNI...')
#1 /var/www/x1db-php/library/X1/Db/Adapter.php(103): X1\Db\Statement->__construct(Object(X1\Db\Adapter\Firebird), Object(X1\ORM\ModelQuery), NULL)
#2 /var/www/x1db-php/library/X1/Db/Adapter/Firebird.php(149): X1\Db\Adapter->query(Object(X1\ORM\ModelQuery), NULL)
#3 /var/www/x1db-php/library/X1/ORM/Query.php(321): X1\Db\Adapter\Firebird->fetchAll(Object(X1\ORM\ModelQuery), NULL, 2)
#4 /var/www/x1db-php/library/X1/ORM/ModelQuery.php(209): X1\ORM\Query->fetchAll(2)
#5 /var/www/x1db-php/webapps/kgrep/service/StatementsUtil.php(97): X1\ORM\ModelQuery->fetchAll()
#6 /var/www/x1db-php/webapps/kgrep/service/KgUtil.php(77): KGREP\Service\StatementsUtil::GetStatements()
#7 /var/www/x1db-php/webapps/kgrep/controllers/PostController.php(27): KGREP\Service\KgUtil->GetDataLimits()
#8 /var/www/x1db-php/library/X1/MVC/Control.php(98): KGREP\Controller\PostController->index()
#9 /var/www/x1db-php/library/X1/MVC/Control.php(66): X1\MVC\Control->tryAction('index')
#10 /var/www/x1db-php/library/X1/MVC/Controller.php(60): X1\MVC\Control->run(Object(X1\MVC\Request))
#11 /var/www/x1db-php/library/X1/MVC/Dispatcher.php(82): X1\MVC\Controller->run(Object(X1\MVC\Request))
#12 /var/www/x1db-php/library/X1/App/FrontController.php(249): X1\MVC\Dispatcher->dispatch()
#13 /var/www/x1db-php/public/index.php(36): X1\App\FrontController->run()
#14 {main}

Последний sql запрос:

select  "ORGUNITS".* from "ORGUNITS"
left join "ORGUNIT_TYPES" as "ORGUNIT_TYPES" on ("ORGUNIT_TYPES"."SYS_GUID"="ORGUNITS"."TYPEFK")  
where 
 mod(coalesce("ORGUNITS"."SYS_STATE",0),2)=0
  and  ("ORGUNITS"."SYS_PARENTGUID" is null)
  and  ("ORGUNIT_TYPES"."TYPE_CODE" not in ('5','1')) 
 order by "ID"