Kohana ORM генерирует запрос, но при его выполнении происходит ошибка, подскажите пожалуйста, что в нем не так?
Database_Exception [ 1064 ]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `order`.`author_id` = `oa`.`user_id`) AND `supplier_id` = '25' AND `status' at line 1 [ SELECT COUNT(`order`.`id`) AS `records_found` FROM `orders` AS `order` WHERE EXISTS (SELECT `order_archive` AS `oa` WHERE `order`.`author_id` = `oa`.`user_id`) AND `supplier_id` = '25' AND `status_id` <> 4 AND (`allow_group` = 'suppliers' OR `allow_group` = 'all') ]
$active_orders_count_all = ORM::factory('Order')
->where(null, 'EXISTS', DB::expr('(SELECT `order_archive` AS `oa` WHERE `order`.`author_id` = `oa`.`user_id`)'))
->and_where('supplier_id', '=', $this->user->id)
->and_where('status_id', '<>', 4)
->and_where_open()
->where('allow_group', '=', 'suppliers')
->or_where('allow_group', '=', 'all')
->and_where_close();
->count_all();