0

我的模型中有一个一对多的单向关系。AUser有许多之一Status

使用原则,这些被映射为单向多对多,其中一个连接列具有唯一约束。

我想使用 symfony 表单从状态表中选择状态,提交表单并让 symfony 保持关系。

我尝试了两种方法:

  1. 但是,使用 Entity 表单类型会产生错误(由于多对多关系原则期望接收一个实例ArrayCollection而不是单个状态对象。

  2. 使用集合实体对象。当使用这种方法时,一个带有 id 的空 divstatus会在表单中呈现。正如我所期望的那样,会出现一个包含状态选项的选择框。

这是代码。我哪里错了?

实体代码:

/**
 * @ORM\ManyToMany(targetEntity="Status")
 */
protected $status;

表格类型代码:

 $builder->add('status', 'collection', array(
     'type' => 'entity',
     'allow_add' => true,
     'options' => array(
         'class' => 'SunflyCoreBundle:Status',
         'property' => 'name',
         ))
 );

表单模板代码:

<form action="{{ path('_product_create_process') }}" method="post" {{ form_enctype(form) }}>
  {{ form_widget(form) }} 
 <input type="submit" />
 </form>

页面上呈现的 HTML:

<div id="product_status" data-prototype="STUFF THAT WONT RENDER ON SO"></div>
4

0 回答 0