我试图从一个应该在一次查找中获得所有 ACL 权限的 CakePHP 2.3 应用程序中理解这个查询。我很难跟踪连接和“lft”“rght”节点。
SELECT
theAro.id as AroId,
theAro.parent_id as AroParentId,
theAro.alias as AroAlias,
theAro.model as AroModel,
theAco.id as AcoId,
theAco.parent_id as AcoParentId,
theAco.alias as AcoAlias,
theAco.rght as AcoRight,
permissions._create as CanCreate,
permissions._read as CanRead,
permissions._update as CanEdit,
permissions._delete as CanDelete
FROM acos AS theAco, aros AS theAro INNER JOIN aros_acos AS permissions ON
(permissions.id =
(SELECT permissions.id FROM aros_acos AS permissions INNER JOIN acos AS ruleAco ON
(ruleAco.id = permissions.aco_id) INNER JOIN aros AS ruleAro ON
(permissions.aro_id = ruleAro.id)
WHERE ruleAco.lft <= theAco.lft
AND ruleAco.rght >= theAco.rght
AND theAro.lft >= ruleAro.lft
AND theAro.rght <= ruleAro.rght
ORDER BY
ruleAro.lft DESC,
ruleAco.lft DESC LIMIT 1
)
)WHERE theAco.id = '$actionAcoId' AND permissions._create = 1 ORDER BY theAro.lft ASC