映射FAIL - 实体类“PI\UnidadBundle\Entity\HorasPorUnidad”映射无效 [英] Mapping FAIL - The entity-class 'PI\UnidadBundle\Entity\HorasPorUnidad' mapping is invalid

查看:207
本文介绍了映射FAIL - 实体类“PI\UnidadBundle\Entity\HorasPorUnidad”映射无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm having a problem here and I don't know how to fix it. See I have this two entities:

<?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 我得到这个错误:

But when I run the task php app/console doctrine:schema:validate I get this errors:


[映射] FAIL - 实体类PI\UnidadBundle\Entity\HorasPorUnidad映射无效:

[Mapping] FAIL - The entity-class 'PI\UnidadBundle\Entity\HorasPorUnidad' mapping is invalid:


  • 无法映射关联的PI \UnidadBundle\Entity\HorasPorUnidad#proyectos_id作为标识符,因为目标实体PI\ProyectoBundle\Entity\Proyectos也将一个关联映射为标识符。

  • 加入关联proyectos_id的列必须与目标实体PI\UnidadBundle\Entity\HorasPorUnidad的所有标识符列相匹配,但是缺少id,cliente。

我不知道如何解决他们,所以任何专家的帮助?

And I don't know how to fix them, so any help from experts? What I need to fix here?

推荐答案

您将 mappedBy inversedBy strong>属性在ManyToOne协会,并检查您的关联的另一方:

You foget the mappedBy and inversedBy attributes in the ManyToOne assocciation and also check the other side of your assocciations:

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

这篇关于映射FAIL - 实体类“PI\UnidadBundle\Entity\HorasPorUnidad”映射无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆