我有2个实体,InProveedorProducto有一个id_producto字段,InOrdenCompraDetalle有一个采购订单的详细信息,包括id_producto字段。 InProveedorProducto在一个包含id_producto但也包含id_proveedor的表中,这意味着该表包含每个提供者的产品列表。
所以,我的TYPE形式:
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';
}
}
我的实体InProveedorProducto
class InProveedorProducto
{
/**
* @ORM\ManyToMany(targetEntity="InOrdenCompraDetalle", inversedBy="productoOc")
* @ORM\JoinTable(name="InCompraDetalleProveedorProducto")
*/
protected $producto;
我的实体InOrdenCompraDetalle
lass InOrdenCompraDetalle
{
/**
* @ORM\ManyToMAny(targetEntity="InProveedorProducto", mappedBy="producto")
*/
protected $productoOc;
请您告诉我为什么在尝试保存到数据库时出现此错误:
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
请帮忙
答案 0 :(得分:0)
我认为这是因为您忘记在__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();
}
}