[英]Doctrine Association Mapping OneToMany Bidirectional do not work
我使用主义ORM生成一对多的双向关联,但是当我执行orm:validation-scheme命令时,这向我显示了以下消息:
“ C:\\ xampp \\ htdocs \\ Gestor \\ vendor \\ bin>主义模块orm:validate-schema [映射]失败-实体类'Empleados \\ Entity \\ TipoDocumento'映射无效:*关联Empleados \\ Entity \\ TipoDocumento#empleados引用不存在的拥有方字段Empleados \\ Entity \\ Empleado#tipodocumento。
[数据库]失败-数据库架构与当前映射文件不同步。”
代码: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;
//...
}
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();
}
}
我基于http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html中的Doctrine文档示例
在TipoDocumento
类中, private $empleados;
应该是private $empleado;
。
编辑抱歉,没错,我在文档中找错了位置。
多对一那里有复数。 它还包含如下内容:
public function __construct() {
$this->empleados = new ArrayCollection();
}
我不能告诉您的类是否包含此功能。
jmarkmurphy感谢您的帮助。 问题出在“ TipoDocumento”类的驼峰箱中,由于某种原因,Doctrine不喜欢驼峰箱……我所做的就是将该类重命名为Tipo_documento,并进行了更改,一切开始正常运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.