2016-09-25 3 views
0

Ich habe 2 Entitäten, InProveedorProducto, die ein id_producto Feld und InOrdenCompraDetalle hat, die ein Detail einer Bestellung hat, einschließlich id_producto Feld zu. InProveedorProducto in einer Tabelle, die id_producto, aber auch id_proveedor hat, bedeutet dies, dass diese Tabelle eine Liste von Produkten für jeden Anbieter enthält.Wie Sie ein Feld aus der ManyToMany-Beziehung speichern? Symfony2

Also, meine TYPE Form:

class InOrdenCompraDetalleType extends AbstractType 
{ 
    /** 
    * @param FormBuilderInterface $builder 
    * @param array $options 
    */ 
    protected $idProveedor; 

    protected $idEmpresaa; 

    public function __construct ($id_proveedor,$id_empresaa) 
    { 
     $this->idProveedor = $id_proveedor; 
     $this->idEmpresaa = $id_empresaa; 
    } 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder 
      ->add('ordenCompra') 
      ->add('productoOc', 'entity', array(
       'class' => 'NivalInventarioBundle:InProveedorProducto', 
       'query_builder' => function (EntityRepository $er) { 
        return $er->createQueryBuilder('u') 
         ->where('u.idProveedor = '.$this->idProveedor) 
         ->orderBy('u.productoO', 'ASC'); 
       }, 
       'choice_label' => function ($displayname) { 
            return $displayname->getDisplayName();}, 
       'by_reference' => true, 
       'expanded' => false, 
       'placeholder' => 'Seleccione una opción', 
       'mapped' => true, 
       'multiple' => false, 
      )) 
      ->add('cantidad'); 
    } 

    /** 
    * @param OptionsResolverInterface $resolver 
    */ 
    public function setDefaultOptions(OptionsResolverInterface $resolver) 
    { 
     $resolver->setDefaults(array(
      'data_class' => 'Nival\InventarioBundle\Entity\InOrdenCompraDetalle' 
     )); 
    } 

    /** 
    * @return string 
    */ 
    public function getName() 
    { 
     return 'nival_inventariobundle_inordencompradetalle'; 
    } 

} 

Meine Einheit InProveedorProducto

class InProveedorProducto 
{ 

    /** 
    * @ORM\ManyToMany(targetEntity="InOrdenCompraDetalle", inversedBy="productoOc") 
    * @ORM\JoinTable(name="InCompraDetalleProveedorProducto") 
    */ 
    protected $producto; 

Meine Einheit InOrdenCompraDetalle

lass InOrdenCompraDetalle 
{ 
    /** 
    * @ORM\ManyToMAny(targetEntity="InProveedorProducto", mappedBy="producto") 
    */ 
    protected $productoOc; 

Könnten Sie bitte lassen Sie mich wissen, warum ich diese Fehlermeldung erhalten, wenn versuchen, in Datenbank speichern:

Catchable Fatal Error: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be of the type array, object given, called in C:\xampp\htdocs\nival7\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php on line 555 and defined 

Bitte helfen

Antwort

0

Ich denke, es ist, weil Sie dies in Ihrem __constructor()

class InProveedorProducto { 
    public function __construct(){ 
     $this->producto = new \Doctrine\Common\Collections\ArrayCollection(); 
    } 
} 


class InOrdenCompraDetalle { 
    public function __construct(){ 
     $this->productoOc = new \Doctrine\Common\Collections\ArrayCollection(); 
    } 
} 
zu tun vergessen
Verwandte Themen