У меня есть таблица
CREATE TABLE `ap_master_pdcategory` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int(10) unsigned DEFAULT '0',
`name` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`description` text COLLATE utf8mb4_unicode_ci NOT NULL,
`create_user` int(10) unsigned DEFAULT NULL,
`create_date` datetime DEFAULT NULL,
`approval_user` int(11) DEFAULT NULL,
`approval_date` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
и использование crudbooster для пользовательских данных сетки с использованием подзапроса
$this->table = 'ap_master_pdcategory';
$this->primary_key = 'id';
$this->title_field = "name";
$this->button_action_style = 'button_icon';
$this->button_import = FALSE;
$this->button_export = FALSE;
$this->col = [];
$this->col[] = ["label"=>"Name","name"=>"name"];
$this->col[] = ["label"=>"Description","name"=>"description"];
$this->col[] = ["label"=>"Total Sub Product","name"=>"(SELECT count(*) FROM ap_master_pdcategory WHERE ap_master_pdcategory.parent_id = id) as total_sub_product"];
, но таблица столбцов всегда равна нулю или 0