Tenacity from one to many Mongodb doctrines

I am using MongoDb doctrine in my project. I have two documents: Question and QuizzPart.

QuizzPart links to many questions, for that I made the following expression:

/**
 * @var ArrayCollection
 * @MongoDB\ReferenceMany(targetDocument="Question", cascade={"all"})
 */
protected $questions = array();

      

and the question includes one QuizzPart.

/**
*@MongoDB\ReferenceOne(targetDocument="QuizzPart", inversedBy="questions") 
*/
protected $quizzPart ;

      

But in my crud (Sonata admin Bundle) when I create (or edit) the quiz part and try to add some questions to it. The QuizzPart link is missing in my Question Document in the database (But quizzPart links to many questions). I didn't know the origin of this error.

+3


source to share


1 answer


After several hours of research I found a solution, actually the problem was the sonata administration kit (quizzPartAdmin class) and not the declarations of the models: this means the 'by_reference' flag is false:



        $formMapper
        ->add('questions', 'sonata_type_collection', array('label' => 'add a question', 'by_reference' => false)
        , array(
        'edit'     => 'inline',
        'inline'   => 'table',
        'sortable' => 'id',
        )) 
      ;

      

0


source







All Articles