Reputation: 2149
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
Upvotes: 5
Views: 5032
Reputation: 569
You have to add a seperate Admin class for the Catalog Entity.
You can only use the Catalog if you have an CatalogAdmin same as the ProductAdmin. After that you can use the sonata_type_model or sonata_type_model_list formtypes.
Upvotes: 0
Reputation: 13312
Try with multiple option:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name')
->add('catalogs', 'sonata_type_model', array('multiple' => true)
;
}
Upvotes: 10