Symfony 4 @UniqueEntity不适用于GEDMO树复合字段

I seem to have done the set up correctly, but still this does not work, ie, it will not set the database table correctly. In fact it ignores completely the @UniqueEntity annotation.

I am setting up a GEDMO tree, where the title of the category should not be repeated for the same parent_id.

So, looking at the the @UniqueEntity documentation and also at some prior code I built, this should work:

/App/Entity/Category

namespace App\Entity;

use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
 * @Gedmo\Tree(type="nested")
 * @ORM\Entity(repositoryClass="App\Repository\CategoryRepository")
 * @UniqueEntity(
 *  fields={"parent", "title"}, // or fields={"parent_id", "title"}
 *  errorPath="title", 
 *  message="This title is already in use for this parent.") 
 * @ORM\Table(name="categories")
*/

class Category
{

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

/**
 * @ORM\Column(type="string", length=190)
 */
private $title;
.....
/**
 * @Gedmo\TreeParent
 * @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
 * @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE")
 */
private $parent;

....
}

There's actually a similar question in here, without a solution.

If you want checking on the database level you will need to use Doctrine's UniqueConstraint annotation:

/*
 * @ORM\Table(name="categories", uniqueConstraints={
 *     @ORM\UniqueConstraint(name="uq_cat_parent_title", columns={"parent_id", "title"})
 * })
 */

EDIT: Modified my answer to include the name of the index. Doctrine documentation states that it is required.