关联字段“”的类型为“ Doctrine \ Common \ Collections \ Collection | array”的期望值,取而代之的是“ array”

时间:2019-11-18 15:54:04

标签: symfony doctrine sonata-admin symfony-2.7

我正在尝试为实体创建管理页面。

在实体Settings中,我有一个字段calculatorItems

/**
     * @var
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\FuneralCostResource", mappedBy="settings")
     */
    private $calculatorItems ;


    public function __construct()
    {
        $this->calculatorItems = new ArrayCollection();
    }

SettingsAdmin中,我声明了“计算器”标签

->tab('Calculator')
                ->add('calculatorItems', 'collection',[
                    'by_reference' => false,
                    'allow_add' => true,
                    'allow_delete' => true,
                    'prototype' => true,
                    'entry_type' => CalculatorType::class
                ])

这是计算器类型

class CalculatorType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('resourceName', NumberType::class)
            ->add('resourcePrice');
    }

    public function configureOptions(OptionsResolver $resolver)
    {

    }

    public function getBlockPrefix()
    {
        return 'app_bundle_calculator_type';
    }
}

当我尝试为设置添加新记录或更新现有记录时,出现异常:

Expected value of type "Doctrine\Common\Collections\Collection|array" for association field "AppBundle\Entity\Settings#$calculatorItems", got "array" instead.

但是calculatorItems是一个ArrayCollection而不是数组。

0 个答案:

没有答案