简体   繁体   English

主义关联一对一映射不起作用

[英]Doctrine Association Mapping OneToMany Bidirectional do not work

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: 我使用主义ORM生成一对多的双向关联,但是当我执行orm:validation-scheme命令时,这向我显示了以下消息:

"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. “ C:\\ xampp \\ htdocs \\ Gestor \\ vendor \\ bin>主义模块orm:validate-schema [映射]失败-实体类'Empleados \\ Entity \\ TipoDocumento'映射无效:*关联Empleados \\ Entity \\ TipoDocumento#empleados引用不存在的拥有方字段Empleados \\ Entity \\ Empleado#tipodocumento。

[Database] FAIL - The database schema is not in sync with the current mapping fi le." [数据库]失败-数据库架构与当前映射文件不同步。”

The code: Empleado class (many to one side) 代码:Empleado类(很多方面)

<?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): TipoDocumento类(一对多):

<?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 我基于http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html中的Doctrine文档示例

In class TipoDocumento , private $empleados; TipoDocumento类中, private $empleados; should be private $empleado; 应该是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. 我不能告诉您的类是否包含此功能。

jmarkmurphy thanks for your help. jmarkmurphy感谢您的帮助。 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. 问题出在“ TipoDocumento”类的驼峰箱中,由于某种原因,Doctrine不喜欢驼峰箱……我所做的就是将该类重命名为Tipo_documento,并进行了更改,一切开始正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM