Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct()

132 views
Skip to first unread message

Gustavo Villela Goulart

unread,
Nov 10, 2019, 7:13:17 PM11/10/19
to zfbr...@googlegroups.com
Prezados, boa noite.

Esse meu código funcionava bem de uma hora para outra ele parou de funcionar. Será que alguém pode ajudar?
Tenho uma relacionamento many-to-many com uma tabela associativa;
################################################################################
/**
 *
 * @ORM\ManyToMany(targetEntity="Cadastro\Model\Motorista", mappedBy="veiculo")
 *
 */
private $motorista;

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

function getMotorista() {
 return $this->motorista;
}

function setMotorista($motorista)
{
 $this->motorista = $motorista;
}
#########################################################################################

/**
 * @ORM\ManyToMany(targetEntity="Application\Model\Veiculo")
 * @ORM\JoinTable(name="MOTORISTA_VEICULO",
 * joinColumns={@ORM\JoinColumn(name="MOTO_IDMOTORISTA", referencedColumnName="IDPESSOA")},
 * inverseJoinColumns={@ORM\JoinColumn(name="MOTO_IDVEICULO", referencedColumnName="IDCAR")}
 * )
 */
private $veiculo;
public function __construct()
{
 parent::__construct();
 $this->veiculo = new \Doctrine\Common\Collections\ArrayCollection();
}
##############################################################################################

Aqui eu recebo os dados do formulário busco o veiculo e relaciono com o motorista
 $idCarro = $request->getPost("veiculo");
                $veiculo = $em->getRepository("Application\Model\Veiculo")
                    ->find($idCarro);

                # Vincula veiculo
                $mot->setVeiculo($veiculo);

Isso funcionava tinha a seguinte estrutura: Motorista -> Motorista_Veiculo -> Veicuo
Agora estou tomando o seguinte erro:

Fatal error: Uncaught TypeError: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be of the type array, object given, called in /var/www/html/sgt/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 555 and defined in /var/www/html/sgt/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php on line 57
( ! ) TypeError: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be of the type array, object given, called in /var/www/html/sgt/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 555 in /var/www/html/sgt/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php on line 57
Reply all
Reply to author
Forward
0 new messages