Doctrine One-To-Many Relationship Won't Save - Integrity Constraint Violation

大憨熊 提交于 2019-12-01 16:18:22

The problem is that you are not setting the user entity in your history class. The association stuff does not do this automatically.

class UserHistory
{
    public function setUser($user) { $this->user = $user; }

class User
{
    public function addHistory($history)
    {
        $this->history->add($history);
        $history->addUser($this);  // *** This is what you are missing
    }

// In your controller class
$user->addHistory($history);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!