Let's say I have two entities:
1. Product
/**
* @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.Catalog
/**
*
* @ORM\Table()
* @ORM\Entity
*/
class Catalog
{
/**
* @ORM\ManyToOne(targetEntity="Product", inversedBy="catalogs")
*/
private $product;
/**
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
}
My ProductAdmin
:
class ProductAdmin extends Admin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name')
->add('catalogs', 'sonata_type_model')
;
}
}
I can't get catalogs
to be working (something like user=>groups association here: http://demo.sonata-project.org/admin/sonata/user/user/create credentials: admin/admin).
I only get errors: No entity manager defined for class Doctrine\Common\Collections\ArrayCollection
Try with multiple option:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name')
->add('catalogs', 'sonata_type_model', array('multiple' => true)
;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With