doctrine/DoctrineMongoDBBundle

Error using DocumentType on Symfony forms [ODM v2]

Closed this issue · 4 comments

I'm trying to upgrade to Mongo ODM v2, but I've got this error when using DocumentType on a Symfony form field:

Argument 2 passed to Doctrine\ODM\MongoDB\Hydrator\HydratorFactory::hydrate() must be of the type array, boolean given

Example of form:

<?php

...

class DTOfferCampaignFilterType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array                $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('offer', DocumentType::class, [
                'required' => false,
                'multiple' => true,
                'class' => Offer::class,
            ])
            ->add('country', CountryType::class, [
                'required' => false,
                'multiple' => true,
            ])
            ->add('save', ButtonType::class, [
                'label' => 'Filter',
            ]);
    }
}

It's about some wrong data I have in an embed field in offer. Stranger thing is that before upgrade to 4.0RC1 it works ok

Sorry for the late reply - vacation and all 😉

So the error is not with the form type but with your data (e.g. having a bool in an embedded field instead of a document)? If so, the error ist most likely by ODM 2.0 using strict typing. If so, I'd move this to the ODM project so we can try to fail more gracefully in such cases. Can you confirm it's not related to the form type?

Yes, it’s about some data inside my Offer document

Reported in ODM as doctrine/mongodb-odm#2044. Thanks @markitosgv!