学说协会映射OneTomany双向不起作用



我使用学说orm来生成关联一对多双向,但是当我执行ORM:验证:验证 - scheme命令时,这显示了下面的mesaje:

" c: xampp htdocs gestor gestor vendor bin> doctrine-module orm:validate-schema[映射]失败 - 实体级的'empleados entity tipodocumento'映射是我nvalid:*协会Empleados Entity tipodocumento#empleados是指拥有侧面字段empleados entity empleado#不存在的tipodocumento。

[数据库]失败 - 数据库架构与当前映射FI不同步le。"

代码:Empleado类(许多到一侧)

<?php
namespace EmpleadosEntity;
use DoctrineCommonCollectionsArrayCollection as Collection;
use EmpresasEntityEmpresa;
use EmpleadosEntityTipoDocumento;
use DoctrineORMMapping as ORM;
use DocumentosEntityDocumentacion_Empleado;
/**
 * @ORMEntity
 * @ORMTable(name="empleado")
 * 
 */
 class Empleado
 {
     /**
      * @ORMId
      * @ORMGeneratedValue(strategy="AUTO")
      * @ORMColumn(type="integer")
      */
     private $id;
     /**
      * @ORMColumn(type="string",length=30,nullable=false,unique=true)
      */
     private $nro_documento;
    /*
     * @ORMManyToOne(targetEntity="EmpleadosEntityTipoDocumento",inversedBy="empleados")
     * @ORMJoinColumn(name="tipodocumento_id", referencedColumnName="id")
     */
    private $tipodocumento;
 //...
 }

tipodocumento类(一对一):

<?php
// yes, the class are in the same namespace "Empleados"
namespace EmpleadosEntity;
use DoctrineCommonCollectionsArrayCollection;
use DoctrineORMMapping as ORM;
use EmpleadosEntityEmpleado;
/**
 * @ORMEntity
 * @ORMTable(name="tipo_documento")
 */
class TipoDocumento
{
    /**
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     * @ORMColumn(type="integer")
     */
    private $id;
    /**
     * @ORMOneToMany(targetEntity="EmpleadosEntityEmpleado", mappedBy="tipodocumento"))
     */
    private $empleados;
 //.....
    public function __construct()
    {
        $this->empleados = new ArrayCollection();
    }
 }

我是基于http://docs.doctrine-project.org/projects/doctrine-morm/en/latest/reference/reference/Association/association-mapping.html

TipoDocumento类中,private $empleados;应为private $empleado;

编辑对不起,没错,我看着文档中错误的位置。

多对一的人在那里具有复数形式。它还包含以下内容:

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

我无法分辨您的班级是否包含此功能。

jmarkmurphy感谢您的帮助。问题在于" tipodocumento"类的骆驼中,出于某种原因,学说不喜欢骆驼...我所做的就是将课程重命名为tipo_documento,随着这种变化,一切都开始正常工作。

最新更新