Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2.1 Sonata Admin Bundle OneToMany

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

like image 502
acid Avatar asked Oct 03 '12 12:10

acid


1 Answers

Try with multiple option:

 protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
        ->add('name')
        ->add('catalogs', 'sonata_type_model', array('multiple' => true)
        ;
    }
like image 101
gpilotino Avatar answered Oct 08 '22 00:10

gpilotino