Hi,
I think their is a bug in sonata admin with the manytomany association.
Using, Symfony 2.1 DEV with master branch of sonata.
The goal is to select a related product, using the "list" option (so we can use the filters to find our product).
Trying to use sonata_type_collection, sonata_type_model, or sonata_type_model_list, and still having the problem.
Here is the code i'm using :
/// Product Entity ///
class Product
{
public function __toString()
{
return $this->nom;
}
public function __construct()
{
$this->accesoires = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* @var ArrayCollection $accesoires
* @ORM\ManyToMany(targetEntity="Product", inversedBy="accesoiresTo")
* @ORM\JoinTable(name="Product_accesoire",
* joinColumns={@ORM\JoinColumn(name="Product_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="accesoire_id", referencedColumnName="id")}
* )
*/
private $accesoires;
/**
* @ORM\ManyToMany(targetEntity="Product", mappedBy="accesoires")
*/
private $accesoiresTo;
/**
* Add accesoires
*
* @param Cyberl\ApcBundle\Entity\Product $accesoires
* @return Product
*/
public function addProduct(\Cyberl\ApcBundle\Entity\Product $accesoires)
{
$this->accesoires[] = $accesoires;
return $this;
}
/**
* Get accesoires
*
* @return Doctrine\Common\Collections\Collection
*/
public function getAccesoires()
{
return $this->accesoires;
}
/**
* Add accesoireTo
*
* @param Cyberl\ApcBundle\Entity\Product $accesoire
* @return Product
*/
public function addAccesoireTo(\Cyberl\ApcBundle\Entity\Product $accesoireTo)
{
$this->accesoiresTo[] = $accesoireTo;
return $this;
}
/**
* Get accesoiresTo
*
* @return Doctrine\Common\Collections\Collection
*/
public function getAccesoiresTo()
{
return $this->accesoiresTo;
}
///////// ADMIN CLASS ///////
class ProductAdmin extends Admin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('Test')
->add('accesoires' , 'sonata_type_model_list',
array(
'label' => 'Accesoires associés',
'by_reference' => true
)
)
->end()
....
Errors i'm getting :
o entity manager defined for class Doctrine\ORM\PersistentCollection
(same error with by reference set to false, and with sonata_type_model instead of sonata_type_model_list)
With this admin class :
->add('accesoires' , 'sonata_type_collection',
array(
'label' => 'Accesoires associés',
'by_reference' => true
)
I have this error :
INVALID MODE : s50377f83ef8fc_accesoires - type : sonata_type_collection - mapping : 8
(same error with by_reference set to false)
Any solution ?
Thanks for your help.