簡體   English   中英

主義關聯一對一映射不起作用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM