-->

映射FAIL - 实体级“PI \\ UnidadBundle \\实体\\ HorasPorUn

2019-10-19 00:44发布

我在这里有一个问题,我不知道如何解决它。 见我这两个实体:

<?php

namespace PI\ProyectoBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Event\LifecycleEventArgs;

/**
 * @ORM\Entity
 * @ORM\Table(name="proyectos")
 * @ORM\Entity(repositoryClass="PI\ProyectoBundle\Entity\Repository\ProyectosRepository")
 * @ORM\HasLifecycleCallbacks
 */
class Proyectos {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length=45, unique=true, nullable=false)
     */
    protected $nombre;

    /**
     * @ORM\Column(type="boolean", nullable=true)
     */
    protected $estado;

    /**
     * @ORM\Column(type="string", length=45, nullable=false)
     */
    protected $pais;

    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="PI\ClienteBundle\Entity\Clientes", cascade={"all"})
     * @ORM\JoinColumn(name="cliente", referencedColumnName="id")
     */
    protected $clientes;

    /**
     * @ORM\ManyToMany(targetEntity="PI\CentroBundle\Entity\Centros", inversedBy="proyectos", cascade={"persist"})
     * @ORM\JoinTable(name="proyectos_has_centros",
     *      joinColumns={@ORM\JoinColumn(name="proyectos_id", referencedColumnName="id"),
     *                   @ORM\JoinColumn(name="proyectos_cliente", referencedColumnName="cliente")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="centros_id", referencedColumnName="id")}
     *      )
     */
    protected $centros;

    /**
     * @ORM\ManyToMany(targetEntity="Application\Sonata\UserBundle\Entity\User", cascade={"persist"})
     * @ORM\JoinTable(name="proyectos_has_system_user",
     *      joinColumns={@ORM\JoinColumn(name="proyectos_id", referencedColumnName="id"),
     *                   @ORM\JoinColumn(name="proyectos_cliente", referencedColumnName="cliente")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="system_user_id", referencedColumnName="id")}
     *      )
     */
    protected $ingenieros;

    public function __construct() {
        $this->centros = new \Doctrine\Common\Collections\ArrayCollection();
        $this->ingenieros = new \Doctrine\Common\Collections\ArrayCollection();
    }

    public function getId() {
        return $this->id;
    }

    public function setNombre($nombre) {
        $this->nombre = $nombre;
    }

    public function getNombre() {
        return $this->nombre;
    }

    public function setEstado($estado) {
        $this->estado = $estado;
    }

    public function getEstado() {
        return $this->estado;
    }

    public function setPais($pais) {
        $this->pais = $pais;
    }

    public function getPais() {
        return $this->pais;
    }

    public function setClientes(\PI\ClienteBundle\Entity\Clientes $clientes) {
        $this->clientes = $clientes;
    }

    public function getClientes() {
        return $this->clientes;
    }

    public function setCentros(\PI\CentroBundle\Entity\Centros $centros) {
        $this->centros[] = $centros;
    }

    public function getCentros() {
        return $this->centros;
    }

    public function setIngenieros(\BIT\UserBundle\Entity\User $ingenieros) {
        $this->ingenieros[] = $ingenieros;
    }

    public function getIngenieros() {
        return $this->ingenieros;
    }

    /**
     * @ORM\PrePersist
     */
    public function prePersist(LifecycleEventArgs $eventArgs) {
        $em = $eventArgs->getEntityManager();
        $q = $em->createQuery('SELECT MAX(p.id) FROM PIProyectoBundle:Proyectos p');
        $id = $q->getSingleResult(\Doctrine\ORM\Query::HYDRATE_SINGLE_SCALAR);
        $this->id = $id + 1;
    }

}

而这个其他:

<?php

namespace PI\UnidadBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="horas_por_proyectos")
 */
class HorasPorUnidad {

    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="Application\Sonata\UserBundle\Entity\User", cascade={"all"})
     * @ORM\JoinColumn(name="fos_user_user_id", referencedColumnName="id")
     */
    protected $fos_user_user_id;

    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="PI\UnidadBundle\Entity\Unidades", cascade={"all"})
     * @ORM\JoinColumn(name="fos_user_user_id", referencedColumnName="id")
     */
    protected $unidades_id;

    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="PI\CentroBundle\Entity\Centros", cascade={"all"})
     * @ORM\JoinColumn(name="centros_id", referencedColumnName="id")
     */
    protected $centros_id;

    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="PI\ProyectoBundle\Entity\Proyectos", cascade={"all"})
     * @ORM\JoinColumn(name="proyectos_id", referencedColumnName="id")
     */
    protected $proyectos_id;

    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="PI\ClienteBundle\Entity\Clientes", cascade={"all"})
     * @ORM\JoinColumn(name="proyectos_cliente", referencedColumnName="id")
     */
    protected $proyectos_cliente;

    /**
     * @ORM\Column(type="date")
     */
    protected $fecha;

    /**
     * @ORM\Column(type="integer")
     */
    protected $horas;

    public function setUserId(\Application\Sonata\UserBundle\Entity\User $user) {
        $this->fos_user_user_id = $user;
    }

    public function getUserId() {
        return $this->fos_user_user_id;
    }

    public function setUnidadesId(\PI\UnidadBundle\Entity\Unidades $unidad) {
        $this->unidades_id = $unidad;
    }

    public function getUnidadesId() {
        return $this->unidades_id;
    }

    public function setCentrosId(\PI\CentroBundle\Entity\Centros $centro) {
        $this->centros_id = $centro;
    }

    public function getCentrosId() {
        return $this->centros_id;
    }

    public function setHoras($cantidad_horas) {
        $this->horas = $cantidad_horas;
    }

    public function getHoras() {
        return $this->horas;
    }

    public function setFecha($fecha) {
        $this->fecha = $fecha;
    }

    public function getFecha() {
        return $this->fecha;
    }

}

但是,当我运行任务php app/console doctrine:schema:validate我得到这个错误:

[映射] FAIL - 实体级 'PI \ UnidadBundle \实体\ HorasPorUnidad' 映射无效:

  • 不能映射协会“PI \ UnidadBundle \实体\ HorasPorUnidad#proyectos_id作为标识,因为目标实体‘PI \ ProyectoBundle \实体\ PROYECTOS’也映射关联的标识。
  • 该协会proyectos_id'的连接列必须匹配到目标实体“PI \ UnidadBundle \实体\ HorasPorUnidad”的所有标识列,不过“身份证,cliente”失踪。

我不知道如何解决这些问题,让专家帮助吗? 我需要在这里解决?

Answer 1:

您foget的的mappedByinversedBy在多对一assocciation属性,并检查您的assocciations的另一面:

 /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="PI\ClienteBundle\Entity\Clientes",inversedBy="?" cascade={"all"})
     * @ORM\JoinColumn(name="cliente", referencedColumnName="id")
     */
    protected $clientes;


文章来源: Mapping FAIL - The entity-class 'PI\\UnidadBundle\\Entity\\HorasPorUnidad' mapping is invalid