ManyToMany不允许使用Nullable

时间:2013-08-29 16:08:20

标签: symfony doctrine-orm symfony-2.3

我有这样的场景:

跟踪ManyToMany乐器

我以这种方式创建表单:

$builder
     ->add('instruments', 'entity_hidden', array(
                           'attr' => array('class' => 'one_req'),
                           'label' => 'form.instrument',
                           'translation_domain' => 'label',
                           'required' => false,
                           'class' => 'Acme\DemoBundle\Entity\Instrument'
                               ))

“hidden_​​entity”由您可以在此处找到的自定义转换器提供:gist

虽然我认为这不是问题。

问题是用户甚至可能不会选择任何工具(例如"required" => false指定的其他工具)。

当我去保存我的返回时出现此错误:

Neither the property 'instruments' nor one of the methods 'setInstruments()',
'__set()' or '__call()' exist and have public access in 
class 'Acme\DemoBundle\Entity\SoundtrackVersion'.

我不明白为什么......

我在哪里做错了?

1 个答案:

答案 0 :(得分:1)

这听起来非常明显,但错误不能说谎。检查Acme\DemoBundle\Entity\SoundtrackVersion实体是否具有属性instruments以及方法setInstruments()getInstruments()