多対多の関係を持つモデルからの埋め込みフォームに問題があります。埋め込みフォームはモデルを正しく保存しますが、多対多の関係は保存しません。
例:
スキーマ.yml:
Mother:
columns:
name:
type: string(80)
Color:
columns:
name:
type: string(80)
Child:
columns:
mother_id:
type: integer
name:
type: string(80)
relations:
Mother:
class: Mother
local: mother_id
foreign: id
type: one
onDelete: cascade
foreignType: one
foreignAlias: Children
FavoriteColors:
class: Color
refClass: ChildColor
local: child_id
foreign: color_id
onDelete: cascade
foreignAlias: Children
ChildColor:
columns:
child_id:
type: integer
color_id:
type: integer
次に、MotherForm.class.php を変更します。
class MotherForm extends BaseMotherForm
{
public function configure()
{
$this->embedForm('child', new ChildForm($this->getObject()->getChildren()));
}
}
および ChildForm.class.php:
class ChildForm extends BaseChildForm
{
public function configure()
{
unset($this['mother_id']);
}
}
私はドクトリンでモジュールを生成します:
php symfony doctrine:generate-module frontend mother Mother
いくつかの色データを入れます:
Color:
Color_1:
name: blue
Color_2:
name: red
Color_3:
name: green
Color_4:
name: purple
/frontend_dev.php/mother/new を呼び出すと、新しい名前を追加できます。母と子の名前は更新されますが、お気に入りの色は保存されません...
phpmyadmin を使用して色と子の間に関係を追加し、次に /edit を呼び出すとします。次に、選択した複数選択に正しい色がありますが、編集できません。
Symfony のバグですか、それとも何か他のことをする必要がありますか?
更新: モデル Child のモジュールを生成するとします。好きな色を編集できるのですが、フォームが埋め込まれなくなりました...