Symfony:获取 sfGuardPermissions 和拥有它们的 sfGuardGroups 列表的最有效方法

发布于 2024-11-30 16:50:08 字数 1864 浏览 5 评论 0原文

我正在开发一个自定义管理界面,用于管理 sfGuardGroupPermission 记录,基本上允许用户在一个界面中为系统中的所有用户组授予/删除权限。

我使用的查询在直接在数据库中执行时工作正常,但是当通过 Doctrine 执行和水合时,它的大部分记录似乎都被删除了。

考虑以下示例:

  • 我在 sf_guard_group_permission 表中有 1 条记录
  • 我在 sf_guard_permission 表中有 62 条记录
  • I sf_guard_group 表中有 42 条记录

我使用 Doctrine_RawSql 对象来构造查询,如下所示

$q->select('{p.*}, {gp.*}, {g.*}')
                ->from('sf_guard_permission p
                    LEFT OUTER JOIN sf_guard_group_permission gp ON p.id = gp.permission_id
                    LEFT OUTER JOIN sf_guard_group g ON g.id = gp.group_id')
                ->addComponent('gp', 'sfGuardGroupPermission gp')
                ->addComponent('p', 'gp.Permission p')
                ->addComponent('g', 'gp.Group g');

:如果我使用 getSqlQuery() 获取原始 sql,我会得到以下内容(返回正确的结果 - 具有这些权限的任何组留下的所有权限的列表...

SELECT gp.group_id AS gp__group_id, gp.permission_id AS gp__permission_id, gp.created_at AS gp__created_at, gp.updated_at AS gp__updated_at, p.id AS p__id, p.name AS p__name, p.description AS p__description, p.section_model_id AS p__section_model_id, p.created_at AS p__created_at, p.updated_at AS p__updated_at, g.id AS g__id, g.name AS g__name, g.description AS g__description, g.created_at AS g__created_at, g.updated_at AS g__updated_at 
    FROM sf_guard_permission p 
    LEFT OUTER JOIN sf_guard_group_permission gp 
         ON p.id = gp.permission_id 
    LEFT OUTER JOIN sf_guard_group g 
         ON g.id = gp.group_id

当我运行查询时通过doctrine和var_dump我得到的Doctrine_Collection,我只得到了2条记录。第一条记录对应于我表中的sf_guard_group_permission记录(正确),第二条记录有。 group_id 为 null,但包含一些有效的 sf_guard_permission 信息 这似乎有点奇怪

I'm working on a custom admin interface for managing sfGuardGroupPermission records, basically allowing the user to grant/remove permissions for all user groups across the system in one interface.

The query I'm using works fine when executed directly in the database, but when being executed and hydrated via Doctrine it seems to have most of its records stripped out.

Consider the following example:

  • I have one record in the sf_guard_group_permission table
  • I have 62 records in the sf_guard_permission table
  • I have 42 records in the sf_guard_group table

I am using a Doctrine_RawSql object to construct the query, this looks as follows:

$q->select('{p.*}, {gp.*}, {g.*}')
                ->from('sf_guard_permission p
                    LEFT OUTER JOIN sf_guard_group_permission gp ON p.id = gp.permission_id
                    LEFT OUTER JOIN sf_guard_group g ON g.id = gp.group_id')
                ->addComponent('gp', 'sfGuardGroupPermission gp')
                ->addComponent('p', 'gp.Permission p')
                ->addComponent('g', 'gp.Group g');

And if I get the raw sql using getSqlQuery() I get the following (which returns the correct result - a list of all permissions left joined by any groups that have these permissions...

SELECT gp.group_id AS gp__group_id, gp.permission_id AS gp__permission_id, gp.created_at AS gp__created_at, gp.updated_at AS gp__updated_at, p.id AS p__id, p.name AS p__name, p.description AS p__description, p.section_model_id AS p__section_model_id, p.created_at AS p__created_at, p.updated_at AS p__updated_at, g.id AS g__id, g.name AS g__name, g.description AS g__description, g.created_at AS g__created_at, g.updated_at AS g__updated_at 
    FROM sf_guard_permission p 
    LEFT OUTER JOIN sf_guard_group_permission gp 
         ON p.id = gp.permission_id 
    LEFT OUTER JOIN sf_guard_group g 
         ON g.id = gp.group_id

When I run the query through doctrine and var_dump my resulting Doctrine_Collection, I am only given 2 records. The first record corresponds with the sf_guard_group_permission record I have in my table (correct), the second record has a group_id of null, but contains some valid sf_guard_permission information. It seems a bit strange.

Can someone maybe suggest where I'm going wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱格式化 2024-12-07 16:50:08

对于其他需要这个的人...我的查询错误:

$q = Doctrine_Query::create()
        ->from('sfGuardPermission p')
        ->leftJoin('p.sfGuardGroupPermission gp')
        ->leftJoin('gp.Group g')
        ->leftJoin('p.sfGuardSectionModel sm');

For anyone else needing this... I just had my query wrong:

$q = Doctrine_Query::create()
        ->from('sfGuardPermission p')
        ->leftJoin('p.sfGuardGroupPermission gp')
        ->leftJoin('gp.Group g')
        ->leftJoin('p.sfGuardSectionModel sm');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文