原则实体一对多关系将外键保存为NULL


Doctrine entity one-to-many relationship saves foreign key as NULL

我环顾四周,发现这个问题doctrine2 OneToMany关系插入NULL,因为外键与此类似,但没有适合我的答案。

在Zend Framework 1.6中使用Doctrine 2和类的名称空间构建,Doctrine使用其迁移工具构建了模式。

我下面的代码:

http://pastie.org/3634009

您是否偶然错过了"双重绑定"实体。也就是说,你需要做例如:

$forum = .... // some forum
$thread = .... // new thread;
$forum->getThreads()->add($thread); // first add to list
$thread->setForum($forum); // but also set forum parent within `Thread`

然后像往常一样持久化实体。。。