ManyToMany关系的EntityType

问题描述 投票:-1回答:1

我在两个实体Ad和City之间存在ManyToMany关系,现在我正在处理AdType表单,提交后出现此错误

Could not determine access type for property "cities" in class "App\Entity\Ad": The property "cities" in class "App\Entity\Ad" can be defined with the methods "addCity()", "removeCity()" but the new value must be an array or an instance of \Traversable, "App\Entity\City" given...

如果我必须使用CollectionType,我需要能够从数据库中加载我的选择,并且我只需要选择一个城市

AdType.php

->add(
                'cities',
                EntityType::class,
                $this->getConfiguration(
                    "Ville",
                    "Sélectionnez votre ville",
                    [
                        'class' => 'App\Entity\City',
                        'choice_label' => 'name'
                    ]
                )
            )

Ad.php

/**
 * @ORM\ManyToMany(targetEntity="App\Entity\City", inversedBy="ads")
 */
private $cities;
php symfony many-to-many symfony-forms
1个回答
0
投票

尝试并让我知道是否可行,因为一旦我遇到同样的问题:

© www.soinside.com 2019 - 2024. All rights reserved.