从SonataUserBundle中的组中获取用户

时间:2017-10-09 01:39:37

标签: symfony doctrine many-to-many fosuserbundle sonata-user-bundle

我需要从群组中获取用户。它似乎存在一个多任务的单向,我想双向进行。

我有

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
              http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="Application\Sonata\UserBundle\Entity\Group" table="fos_user_group">

    <id name="id" column="id" type="integer">
        <generator strategy="AUTO" />
    </id>
    <many-to-many field="users" mapped-by="groups" target-entity="Application\Sonata\UserBundle\Entity\User">

    </many-to-many>

</entity>

</doctrine-mapping>

在我的GroupAdmin

$formMapper
    ->with('General', array('class' => 'col-md-6'))
    ->add('name')
    ->add('users', 'entity', array(
        'class' => 'Application\Sonata\UserBundle\Entity\User',

        'query_builder' => function (EntityRepository $er) {
            return $er->createQueryBuilder('u')
                ->where('u.username <> :superadmin')
                ->setParameter('superadmin', 'superadmin')
                ->orderBy('u.lastname', 'ASC');
        },
        'label' => 'Usuaris',
        'choice_label' => 'cognomNomUsername',
        'multiple' => true,
        'expanded' => true
    ));

但更新表单后,更改不会保存。我做错了什么?

0 个答案:

没有答案