jjaybrown98
jjaybrown98

Reputation: 89

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

I've looked around and this question doctrine2 OneToMany relationship inserts NULL as the foreign key is similar to this one but without an answer that works for me.

Build in Zend Framework 1.6 using Doctrine 2 and name spaces for classes, Doctrine has build the schema using it's migration tool.

My codes below:

http://pastie.org/3634009

Upvotes: 3

Views: 1471

Answers (1)

Jovan Perovic
Jovan Perovic

Reputation: 20193

Did you by some chance miss to "double bind" entities. That is, you need to do for example:

$forum = .... // some forum
$thread = .... // new thread;

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

and then persist entities as usual...

Upvotes: 4

Related Questions