Ошибка при сохранении внедренного документа с DoctrineMongoDB: задан массив

Я работаю над проектом с использованием Doctrine-MongoDB и Symfony.

Я встроил документ в другое использование \@EmbedMany аннотаций.

Вот документы:

MusicalInfos:

<?php
// app/Resources/Document/Musical.php

namespace AppBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * @MongoDB\Document(collection="bv_musical_infos")
 */
class MusicalInfos
{
        /**
         * @MongoDB\Id(strategy="auto")
         */
        protected $id;

        /**
         * @MongoDB\ReferenceOne(targetDocument="User")
         */
        protected $user;

        /**
         * @MongoDB\EmbedMany(targetDocument="InstrumentsPlayed")
         */
        protected $instruments = array();

И вложенный документ:

<?php

namespace AppBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * @MongoDB\EmbeddedDocument
 */
class InstrumentsPlayed
{
        /**
         * @MongoDB\ReferenceOne(targetDocument="Instruments")
         */
        protected $instrument;

        /**
         * @MongoDB\Field(type="int")
         */
        protected $practiceLevel;

После этого я создал форму для заполнения этих документов:

<?php

namespace AppBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class MusicalInfosType extends AbstractType
{
        private $dm;

        public function __construct($dm)
        {   
                $this->dm = $dm;
        }   

        public function buildForm(FormBuilderInterface $builder, array $options)
        {   
                $builder->add('instruments', 'collection', array(
                                'type' => new InstrumentsPlayedType($this->dm),
                                'allow_add' => true,
                                'allow_delete' => true
                )); 
        }   

        public function setDefaultOptions(OptionsResolverInterface $resolver)
        {   
                    $resolver->setDefaults(array(
                                    'data_class' => 'AppBundle\Document\MusicalInfos',
                                        )); 
        }   

        public function getName()
        {   
                return 'musical_infos';
        }   
}

контроллер

<?php
//...
                if('POST' === $request->getMethod()) {
                        $form->bind($request);
                        if($form->isValid()) {
                                $user = $this->container->get('security.context')->getToken()->getUser();
                                $musicalInfos->setUser($user);
                                $dm->persist($musicalInfos);
                                $dm->flush();

                                $response = new JsonResponse();
                                $response->setData(array('registred_musical' => true));

                                return $response;
                        }

Но когда я пытаюсь это сделать, я всегда получаю следующее исключение: Предупреждение: spl_object_hash() ожидает, что параметр 1 будет объектом, массив задан

Я не знаю почему...

Спасибо за вашу помощь!

0 ответов

Другие вопросы по тегам