给定以下表结构:
CREATE TABLE IF NOT EXISTS `roles` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(32) NOT NULL,
`description` varchar(255) NOT NULL,
`parent` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
是否有可能以首先返回孩子的方式查询它(自下而上)。
1, user, Login privileges, granted after account confirmation, 17
2, admin, Administrative user, has access to everything., NULL
15, unverified, Users who have not validated their email address, NULL
16, verified, Users who have validated their email address, NULL
17, guest, A guest role, an anonymous visitor with no account, NULL
18, moderator, Role for doing staff duties, 1
目标是将这些加载到 Zend_Acl 的addRole
方法中,该方法需要在添加子项之前添加角色。
我当前的方法是次优的(并且可能是错误的),需要 2 个查询。一个获取所有叶节点(其中父节点为 NULL),另一个获取父节点排序的父节点(DESC)。
任何帮助总是非常感谢。