N
N
Nikita Gusakov2013-04-06 23:25:53
symfony
Nikita Gusakov, 2013-04-06 23:25:53

Deal with data insertion in Doctrine?

Here is the part of the config where the links are described:

Dog:
    oneToMany:
        dogs:
            targetEntity: Dog
            mappedBy: post
            cascade:
                - persist
Post:
    manyToOne:
        post:
            targetEntity: Post
            inversedBy: dogs
        joinColumns:
            post_id:
                referencedColumnName: id

And here is the controller part:
$post = new Entity\Post();<br>
$form = $this->createForm(new Form\PostType(), $post);<br>
if( $request->isMethod('POST') && $form->bind($request)->isValid() ) {<br>
    $post = $form->getData()->setAddDate();<br>
    $em = $this->getDoctrine()->getManager();<br>
    $em->persist($post);<br>
    $em->flush();<br><br>
//            return $this->redirect($this->generateUrl('show', array('id' => $post->getId())));<br>
}<br>

All data is inserted correctly, except for the link itself - why? null is substituted for post_id.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Romanenko, 2013-04-07
@hell0w0rd

OK.
Let's go from the start.
put the description of the entity, the form and the controller with the method in the gist.

S
Sergey, 2013-04-07
Protko @Fesor

Your config is strange... Either your targetEntity is incorrect (on the contrary, put down the name of the entities) or I don't understand the structure of your database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question