当我创建一个类别时,这是代码工作正常,当我们创建一个子类别时它会出错。
在实体文件中:
/**
* Music\Bundles\Core\Entity\MusicCategory
* @ORM\Table(name="ms_musiccategory")
* @ORM\Entity()
* @ORM\Entity(repositoryClass="Music\Bundles\Core\Entity\Repository\CategoryRepository")
* @UniqueEntity(fields={"name"},message="The name is already in this system.")
*/
class MusicCategory
{
/**
* @ORM\Column(name="id",type="integer")
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
*@ORM\ManyToOne(targetEntity="MusicCategory")
*@ORM\JoinColumn(name="parent_Id", referencedColumnName="id")
*
*/
private $parentid;
在表单生成器中:
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('name')
->add('description')
->add('parentid', 'entity', array('class'=>'MusicCoreBundle:MusicCategory',
'property' => 'name',
'required' => false,
'query_builder' => function(EntityRepository $er) {return $er->createQueryBuilder('s')->orderBy('s.name', 'ASC');},
'empty_value' => 'No category'
));
}