带有连接列的Doctrine 2实体插入空值

时间:2014-07-18 20:47:33

标签: php doctrine-orm zend-framework2

我最有可能做错了什么,但我有一个这样的实体,插入时,为其user_id列插入NULL(尽管我设置了它)。

/**
 * @ORM\Entity
 * @ORM\Table(name="sales_contacts_tags")
 */
class SalesContactTag
{

    /**
     * @ORM\Id
     * @ORM\Column(type="integer");
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;


    /**
     * @ORM\Column(type="integer");
     */
    protected $user_id;

    /**
     * @ORM\Column(type="integer");
     */
    protected $sales_contact_id;


    /**
     * @ORM\Column(type="datetime");
     */
    protected $time_recorded;


    /**
     * @ORM\Column(type="string");
     */
    protected $type;


    /**
     * @var \Foo\Entity\User $user
     * @ORM\OneToOne(targetEntity="Foo\Entity\User", fetch="EAGER")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
     */
    protected $user;

    /**
     * @param mixed $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param mixed $sales_contact_id
     */
    public function setSalesContactId($sales_contact_id)
    {
        $this->sales_contact_id = $sales_contact_id;
    }

    /**
     * @return mixed
     */
    public function getSalesContactId()
    {
        return $this->sales_contact_id;
    }

    /**
     * @param mixed $time_recorded
     */
    public function setTimeRecorded($time_recorded)
    {
        $this->time_recorded = $time_recorded;
    }

    /**
     * @return mixed
     */
    public function getTimeRecorded()
    {
        return $this->time_recorded;
    }

    /**
     * @param mixed $type
     */
    public function setType($type)
    {
        $this->type = $type;
    }

    /**
     * @return mixed
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * @param mixed $user_id
     */
    public function setUserId($user_id)
    {
        $this->user_id = $user_id;
    }

    /**
     * @return mixed
     */
    public function getUserId()
    {
        return $this->user_id;
    }

    /**
     * @param \LaunchfireUser\Entity\User $user
     */
    public function setUser($user)
    {
        $this->user = $user;
    }

    /**
     * @return \LaunchfireUser\Entity\User
     */
    public function getUser()
    {
        return $this->user;
    }

}

当我获取其中一个实体时,一切都很好。多个关系实体按预期列出。但是,当我插入时,user_id列为空。

有什么想法吗?

感谢您一如既往的帮助。

1 个答案:

答案 0 :(得分:5)

您的user_iduser字段相互冲突,因为它们都是" user_id"数据库字段。您最好的选择是删除user_id字段并在保留之前调用setUser()