2013-02-20 73 views
1

我想做什麼:我試圖做一個文件上傳並將其數據保存到數據庫,在官方Symfony 2教程http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html學說不想堅持我的實體,雖然一切都好像

我得到什麼,而不是: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'author' cannot be null

我的實體 - >http://pastebin.com/av0XAASj

我的控制器 - >http://pastebin.com/bQ32UUsa

完整的錯誤的錯誤,我得到的,儘管 '作者' 調用之前設置正確'persist'方法 http://i.imgur.com/crOqDUe.jpg

*我有意將$作者的Entity屬性設置爲public能夠在堅持控制器之前var_dump。當它是私人的問題保持不變。*

回答

1

我發現了什麼問題。問題在我腦海中(當然)。列「作者」是User實體的關係列,因此Author的值應該是User類對象,而不是Integer。

在控制器此是這樣:

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