1

我有两张桌子:

类别
编号 | 姓名
1 | 编程
2 | 设计
3 | PHP
4 | C#
5 | Adobe Photoshop
类别树
类别 ID | parent_id
1 | 无效的
2 | 无效的
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;
}

}

我正在使用选择表单元素在数据库中插入这些值,当我选择任何工作正常的根类别时,但是当我选择根或留空时,这不能在“category_tree”表中插入 NULL 值。如何在“category_tree”表中添加 NULL 值?

4

0 回答 0