5

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

acid
  • 2,099
  • 4
  • 28
  • 41

2 Answers2

10

Try with multiple option:

 protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
        ->add('name')
        ->add('catalogs', 'sonata_type_model', array('multiple' => true)
        ;
    }
gpilotino
  • 13,055
  • 9
  • 48
  • 61
0

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.

sensi
  • 569
  • 4
  • 15