Error instantiating 2 objects with doctrine entities (setter)

1

I can not do the 2 entities relationship and the following error is appearing:

Catchable fatal error: Argument 1 passed to Clientes\Entity\Clientes::setEstado() must be an instance of Estados, instance of Clientes\Entity\Estados given, called in C:\xampp\htdocs\zend_framework\module\Clientes\src\Clientes\Controller\IndexController.php on line 34 and defined in C:\xampp\htdocs\zend_framework\module\Clientes\src\Clientes\Entity\Clientes.php on line 186

Controller

$estado = new \Clientes\Entity\Estados();
$estado->setIdFk('1');
$estado->setEstado('1');

$cliente = new \Clientes\Entity\Clientes();
$cliente->setNome('MEU NOME');

$cliente->setEstado($estado);

$em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
$em->persist($estado);

$em->persist($cliente);
$em->flush();

Entities:

 /**
 * Clientes
 *
 * @ORM\Table(name="clientes", indexes={@ORM\Index(name="fk_estado",      columns={"estado"})})
 * @ORM\Entity
 */
 class Clientes
 {
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer", nullable=false)
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $id;

/**
 * @var string
 *
 * @ORM\Column(name="nome", type="string", length=100, nullable=true)
 */
private $nome;

/**
 * @var string
 *
 * @ORM\Column(name="sobrenome", type="string", length=150, nullable=true)
 */
private $sobrenome;

/**
 * @var string
 *
 * @ORM\Column(name="endereco", type="string", length=100, nullable=true)
 */
private $endereco;

/**
 * @var string
 *
 * @ORM\Column(name="bairro", type="string", length=80, nullable=true)
 */
private $bairro;

/**
 * @var string
 *
 * @ORM\Column(name="complemento", type="string", length=60, nullable=true)
 */
private $complemento;

/**
 * @var string
 *
 * @ORM\Column(name="cidade", type="string", length=50, nullable=true)
 */
private $cidade;

/**
 * @var string
 *
 * @ORM\Column(name="cep", type="string", length=9, nullable=true)
 */
private $cep;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="modificacao", type="datetime", nullable=true)
 */
private $modificacao;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="data", type="datetime", nullable=true)
 */
private $data;

/**
 * @var \Estados
 *
 * @ORM\ManyToOne(targetEntity="Estados")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="estado", referencedColumnName="id_fk")
 * })
 */
private $estado;
...

E

/**
 * Estados
 *
 * @ORM\Table(name="estados")
 * @ORM\Entity
 */
class Estados
{
/**
 * @var \Id
 *
 * @ORM\ManyToOne(targetEntity="Estados")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="estado", referencedColumnName="id_fk")
 * })
 */
private $idFk;

/**
 * @var string
 *
 * @ORM\Column(name="estado", type="string", length=20, nullable=true)
 */
private $estado;
    
asked by anonymous 26.08.2015 / 22:44

1 answer

0

Try changing the mapping from Estados to Clientes to:

/**
 * @var \Estados
 *
 * @ORM\ManyToOne(targetEntity="\Clientes\Entity\Estados")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="estado", referencedColumnName="id_fk")
 * })
 */
private $estado;
    
26.08.2015 / 22:56