假设我有两个实体:
一、产品
/**
* @ORM\Table()
* @ORM\Entity
*/
class Product
{
/*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @ORM\OneToMany(targetEntity="Catalog", mappedBy="product")
*/
public $catalogs;
public function __construct()
{
$this->catalogs = new \Doctrine\Common\Collections\ArrayCollection();
}
}
2.目录
/**
*
* @ORM\Table()
* @ORM\Entity
*/
class Catalog
{
/**
* @ORM\ManyToOne(targetEntity="Product", inversedBy="catalogs")
*/
private $product;
/**
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
}
我的ProductAdmin
:
class ProductAdmin extends Admin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name')
->add('catalogs', 'sonata_type_model')
;
}
}
我无法开始catalogs
工作(类似于 user=>groups 关联:http: //demo.sonata-project.org/admin/sonata/user/user/create credentials: admin/admin)。我只得到错误:No entity manager defined for class Doctrine\Common\Collections\ArrayCollection