-1

我试图从一个应该在一次查找中获得所有 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
4

1 回答 1

1

如果可以的话,打开一个 sql 命令行并尝试运行最简单的查询形式,例如 SELECT theAro.id as AroId FROM aros AS theAro; 现在尝试以逻辑方式连续添加查询的每个路径,重新创建原始查询,并注意它在此过程中所做的事情。即,什么数据消失了,什么数据仍然存在,当您添加更多条件时会出现什么新数据,直到您重新创建整个查询

于 2013-06-12T21:05:05.410 回答