1
我們使用的是FOSRestBundle
。假設我想通過API來創建Ticket
對象與以下JSON體:Symfony 3形式與FOSRestBundle實體的集合
{
"title": "I need help",
"symptoms": [1, 4, 6]
"author": 31
}
作者和症狀陣列在數據庫中引用的主鍵。
我的表單建築看起來像:
$builder->add('title', TextType::class);
$builder->add('author', EntityType::class, [
'class' => User::class
]);
$builder->add('symptoms', CollectionType::class, [
'entry_type' => EntityType::class,
'entry_options' => [
'class' => Symptom::class,
],
]);
的問題是,title
和author
被正確地分配給票據對象但symptoms
數組不轉化爲實體的集合。此外還有一個錯誤,即This form should not contain extra fields
。
如果我想將一個實體集合分配給一個對象,表單構建器應該是什麼樣子?