2

I'm having some problems updating a reference from one collection to another in Symfony2 with mongoDB using Sonata Admin Bundle.

I have created this reference between the users and the communities they can admin.

This one is in the Community class

class Community
{
    /**
     * @MongoDB\ReferenceMany(
     *      targetDocument="User",
     *      inversedBy="communitiesAdmin",
     *  )
     */
    protected $usersAdministrator;

And this one in the User

class User extends BaseUser
{
    /**
     * @MongoDB\ReferenceMany(
     *      targetDocument="Community",
     *      mappedBy="usersAdministrator",
     * )
     */
    protected $communitiesAdmin;

and this is the way I show the field in Sonata

    $formMapper
        ->with('Community Administrators')
            ->add('usersAdministrator', 'sonata_type_model', array('expanded' => true))
        ->end()

When i track the collection in MongoHub the reference is being created but I cannot update it because the data previously inserted is not being shown when I edit the community.

Any idea?

4

1 回答 1

2

修复它:

public function addVideo($video)
{
    $this->videos[] = $video;
    $video->addArtist($this); << This makes doctrine handle the bi direction
}

在管理员中:

        ->add('videos', 'sonata_type_model', array(
            'required' => false,
            'multiple' => true,
            'by_reference' => false
        ))

by_reference = FALSE 真的很重要!

于 2014-04-26T07:02:36.657 回答