1
votes

What I want to do: I am trying to make a file upload and save it's data to database following the official Symfony 2 tutorial at http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html .

What I get instead: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'author' cannot be null

My entity -> http://pastebin.com/av0XAASj

My controller -> http://pastebin.com/bQ32UUsa

The full error error I get, although 'author' is properly set before calling the 'persist' method http://i.imgur.com/crOqDUe.jpg

*I purposefully have set the $author Entity property to public to be able to var_dump it just before persist in controller. When it's private the problem stays the same.*

1

1 Answers

1
votes

I found out what was the problem. Problem was in my head (of course). Column 'author' is a relation column to User entity, therefore instead of an Integer, value of Author should be an User class object.

In controller this goes like:

  $user = $this->getDoctrine()
                    ->getRepository('RepoRepoBundle:User')
                    ->find('4449');
  $document->setUser($user);
  $em->persist($document);
  $em->flush();