0
votes

i use doctrine ORM for generate a association one-to-many bidirectional, but when i execute the orm:validation-scheme command, this shows me the mesaje below:

"C:\xampp\htdocs\Gestor\vendor\bin>doctrine-module orm:validate-schema [Mapping] FAIL - The entity-class 'Empleados\Entity\TipoDocumento' mapping is i nvalid: * The association Empleados\Entity\TipoDocumento#empleados refers to the owning side field Empleados\Entity\Empleado#tipodocumento which does not exist.

[Database] FAIL - The database schema is not in sync with the current mapping fi le."

The code: Empleado class (many to one side)

<?php
namespace Empleados\Entity;

use Doctrine\Common\Collections\ArrayCollection as Collection;
use Empresas\Entity\Empresa;
use Empleados\Entity\TipoDocumento;
use Doctrine\ORM\Mapping as ORM;
use Documentos\Entity\Documentacion_Empleado;

/**
 * @ORM\Entity
 * @ORM\Table(name="empleado")
 * 
 */

 class Empleado
 {
     /**
      * @ORM\Id
      * @ORM\GeneratedValue(strategy="AUTO")
      * @ORM\Column(type="integer")
      */
     private $id;

     /**
      * @ORM\Column(type="string",length=30,nullable=false,unique=true)
      */
     private $nro_documento;

    /*
     * @ORM\ManyToOne(targetEntity="Empleados\Entity\TipoDocumento",inversedBy="empleados")
     * @ORM\JoinColumn(name="tipodocumento_id", referencedColumnName="id")
     */
    private $tipodocumento;

 //...

 }

The TipoDocumento class (one to many side):

<?php
// yes, the class are in the same namespace "Empleados"
namespace Empleados\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Empleados\Entity\Empleado;

/**
 * @ORM\Entity
 * @ORM\Table(name="tipo_documento")
 */

class TipoDocumento
{

    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\OneToMany(targetEntity="Empleados\Entity\Empleado", mappedBy="tipodocumento"))
     */
    private $empleados;

 //.....
    public function __construct()
    {
        $this->empleados = new ArrayCollection();
    }

 }

I'm based on the Doctrine documentation example in http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html

2
Maybe your issues don't have to do with the code, but the database schema itself. This answer stackoverflow.com/a/16550985/2296441 may help deal with the [Database] FAIL, and that might fix your problem. - jmarkmurphy
"[Database] FAIL - The database schema is not in sync with the current mapping fi le." that warning appears because I have the database blank, no tables. I tried first to create the tables without the associations, and add them later, but I got the same error message. - Darwin Carrizo
The only thing I can suggest then is to try creating these classes as they are shown here in this question without any other functions, and see what happens. Take out all unused namespace parts (e.g. use Empresas\Entity\Empresa, use Empleados\Entity\TipoDocumento) and see if you get the same error. - jmarkmurphy
Then once you get the bare bones classes working, you can add stuff back in bit by bit until the error reappears. - jmarkmurphy

2 Answers

0
votes

In class TipoDocumento, private $empleados; should be private $empleado;.

Edit Sorry that's right, I was looking at the wrong place in the documentation.

The Many-to-one has the plural there. It also contains something like:

public function __construct() {
    $this->empleados = new ArrayCollection();
}

I can't tell if your class contains this function.

0
votes

jmarkmurphy thanks for your help. The problem was in the camelcase of the "TipoDocumento" class, for some reason Doctrine does not like the camelcase ... What I did was rename the class to Tipo_documento and with that change everything started to work fine.