Sonata Admin - Bug with ManyToMany with self referencing ? - SF 2.1

1,155 views
Skip to first unread message

EnergieZ

unread,
Aug 24, 2012, 9:23:23 AM8/24/12
to sonat...@googlegroups.com
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.




Andrew Thomas

unread,
Dec 3, 2012, 12:15:23 PM12/3/12
to sonat...@googlegroups.com
Did you manage to resolve this - having same issue

Max Małecki

unread,
Feb 28, 2014, 6:38:18 AM2/28/14
to sonat...@googlegroups.com
I got the same issue here.

jeremy guido

unread,
Mar 14, 2014, 12:27:03 PM3/14/14
to sonat...@googlegroups.com
Hi there,

the sonata_type_model_list doesn't accept a collection as property.
You need to use a sonata_type_model with multiple as true.
Reply all
Reply to author
Forward
0 new messages