Doctrine orm 使用多对多自引用关系在桥接表中添加空值

Doctrine orm 使用多对多自引用关系在桥接表中添加空值,doctrine-orm,null,Doctrine Orm,Null,我有两张桌子: category id | name 1 | Programming 2 | Designing 3 | PHP 4 | C# 5 | Adobe Photoshop 如何在“类别树”表中添加空值?为什么需要空值?如果类别没有父项,您不能在表中什么都不放吗?空值对外键不好。谢谢Florent,我明白了。。。。 category_tree category_id | parent_id 1 | NULL 2 | NULL 3

我有两张桌子:

category id | name 1 | Programming 2 | Designing 3 | PHP 4 | C# 5 | Adobe Photoshop
如何在“类别树”表中添加空值?

为什么需要空值?如果类别没有父项,您不能在表中什么都不放吗?空值对外键不好。谢谢Florent,我明白了。。。。 category_tree category_id | parent_id 1 | NULL 2 | NULL 3 | 1 4 | 1 5 | 2
 /**
 * @ORM\Entity
 * @ORM\Table(name="category")
 */
 class Category
{

/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer", nullable=false)
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
protected $id;
/**
 * @ORM\Column(type="text", name="name")
 */
protected $name;
    /**
 * @ORM\Column(type="text", name="description")
 */

/**
 * @ORM\ManyToMany(targetEntity="Category")
 * @ORM\JoinTable(name="category_tree",
 *      joinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="parent_id", referencedColumnName="id")}
 *      )
 */
protected $categories;




public function __construct()
{
    $this->categories = new \Doctrine\Common\Collections\ArrayCollection();
}

public function addCategory(Category $category)
{
    $this->categories[] = $category;
    return $this;
}

public function getCategories()
{
    return $this->categories;
}

public function getId()
{
    return $this->id;
}

public function setName($name)
{
    $this->name = $name;
    return $this;
}

public function getName()
{
    return $this->name;
}

}