我在这里遇到了一个问题,我不知道如何解决它
<?php
namespace PIProyectoBundleEntity;
use DoctrineORMMapping as ORM;
use DoctrineORMEventLifecycleEventArgs;
/**
* @ORMEntity
* @ORMTable(name="proyectos")
* @ORMEntity(repositoryClass="PIProyectoBundleEntityRepositoryProyectosRepository")
* @ORMHasLifecycleCallbacks
*/
class Proyectos {
/**
* @ORMId
* @ORMColumn(type="integer")
*/
protected $id;
/**
* @ORMColumn(type="string", length=45, unique=true, nullable=false)
*/
protected $nombre;
/**
* @ORMColumn(type="boolean", nullable=true)
*/
protected $estado;
/**
* @ORMColumn(type="string", length=45, nullable=false)
*/
protected $pais;
/**
* @ORMId
* @ORMManyToOne(targetEntity="PIClienteBundleEntityClientes", cascade={"all"})
* @ORMJoinColumn(name="cliente", referencedColumnName="id")
*/
protected $clientes;
/**
* @ORMManyToMany(targetEntity="PICentroBundleEntityCentros", inversedBy="proyectos", cascade={"persist"})
* @ORMJoinTable(name="proyectos_has_centros",
* joinColumns={@ORMJoinColumn(name="proyectos_id", referencedColumnName="id"),
* @ORMJoinColumn(name="proyectos_cliente", referencedColumnName="cliente")},
* inverseJoinColumns={@ORMJoinColumn(name="centros_id", referencedColumnName="id")}
* )
*/
protected $centros;
/**
* @ORMManyToMany(targetEntity="ApplicationSonataUserBundleEntityUser", cascade={"persist"})
* @ORMJoinTable(name="proyectos_has_system_user",
* joinColumns={@ORMJoinColumn(name="proyectos_id", referencedColumnName="id"),
* @ORMJoinColumn(name="proyectos_cliente", referencedColumnName="cliente")},
* inverseJoinColumns={@ORMJoinColumn(name="system_user_id", referencedColumnName="id")}
* )
*/
protected $ingenieros;
public function __construct() {
$this->centros = new DoctrineCommonCollectionsArrayCollection();
$this->ingenieros = new DoctrineCommonCollectionsArrayCollection();
}
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(PIClienteBundleEntityClientes $clientes) {
$this->clientes = $clientes;
}
public function getClientes() {
return $this->clientes;
}
public function setCentros(PICentroBundleEntityCentros $centros) {
$this->centros[] = $centros;
}
public function getCentros() {
return $this->centros;
}
public function setIngenieros(BITUserBundleEntityUser $ingenieros) {
$this->ingenieros[] = $ingenieros;
}
public function getIngenieros() {
return $this->ingenieros;
}
/**
* @ORMPrePersist
*/
public function prePersist(LifecycleEventArgs $eventArgs) {
$em = $eventArgs->getEntityManager();
$q = $em->createQuery('SELECT MAX(p.id) FROM PIProyectoBundle:Proyectos p');
$id = $q->getSingleResult(DoctrineORMQuery::HYDRATE_SINGLE_SCALAR);
$this->id = $id + 1;
}
}
另一个:
<?php
namespace PIUnidadBundleEntity;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity
* @ORMTable(name="horas_por_proyectos")
*/
class HorasPorUnidad {
/**
* @ORMId
* @ORMManyToOne(targetEntity="ApplicationSonataUserBundleEntityUser", cascade={"all"})
* @ORMJoinColumn(name="fos_user_user_id", referencedColumnName="id")
*/
protected $fos_user_user_id;
/**
* @ORMId
* @ORMManyToOne(targetEntity="PIUnidadBundleEntityUnidades", cascade={"all"})
* @ORMJoinColumn(name="fos_user_user_id", referencedColumnName="id")
*/
protected $unidades_id;
/**
* @ORMId
* @ORMManyToOne(targetEntity="PICentroBundleEntityCentros", cascade={"all"})
* @ORMJoinColumn(name="centros_id", referencedColumnName="id")
*/
protected $centros_id;
/**
* @ORMId
* @ORMManyToOne(targetEntity="PIProyectoBundleEntityProyectos", cascade={"all"})
* @ORMJoinColumn(name="proyectos_id", referencedColumnName="id")
*/
protected $proyectos_id;
/**
* @ORMId
* @ORMManyToOne(targetEntity="PIClienteBundleEntityClientes", cascade={"all"})
* @ORMJoinColumn(name="proyectos_cliente", referencedColumnName="id")
*/
protected $proyectos_cliente;
/**
* @ORMColumn(type="date")
*/
protected $fecha;
/**
* @ORMColumn(type="integer")
*/
protected $horas;
public function setUserId(ApplicationSonataUserBundleEntityUser $user) {
$this->fos_user_user_id = $user;
}
public function getUserId() {
return $this->fos_user_user_id;
}
public function setUnidadesId(PIUnidadBundleEntityUnidades $unidad) {
$this->unidades_id = $unidad;
}
public function getUnidadesId() {
return $this->unidades_id;
}
public function setCentrosId(PICentroBundleEntityCentros $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
时,我会得到以下错误:
[映射]失败-实体类"PI\UnidadBundle\entity\HorasPorUnidad"映射无效:
- 无法将关联"PI\UnidadBundle\Entity\HorasPorUnidad#proyectos_id"映射为标识符,因为目标实体"PI\ProjectoBundle\Entity\Projectos"也将关联映射为标识符
- 关联"proyectos_id"的联接列必须与目标实体"PI\UnidadBundle\entity\HorasPorUnidad"的所有标识符列匹配,但缺少"id,cliente"
我不知道如何修复它们,所以有专家的帮助吗?我需要在这里修复什么?
您在ManyToOne关联中设置mappedBy和invertedBy属性,并检查关联的另一侧:
/**
* @ORMId
* @ORMManyToOne(targetEntity="PIClienteBundleEntityClientes",inversedBy="?" cascade={"all"})
* @ORMJoinColumn(name="cliente", referencedColumnName="id")
*/
protected $clientes;