Buenas tardes estoy realizando un proyecto en Symfony 3 en el cual uso Doctrine 2.5.
En dicho proyecto tengo las siguientes tablas:
CREATE TABLE companies (
id_company INT NOT NULL AUTO_INCREMENT,
id_user INT NOT NULL UNIQUE,
name VARCHAR(200) NOT NULL,
address VARCHAR(200) NULL,
phone INT NULL UNIQUE,
email VARCHAR(200) NULL UNIQUE,
createat TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updateat DATETIME NULL,
PRIMARY KEY (id_company),
FOREIGN KEY (id_user) REFERENCES users(id_user)
);
CREATE TABLE faces (
id_face INT NOT NULL AUTO_INCREMENT,
image VARCHAR(200) NOT NULL,
PRIMARY KEY (id_face)
);
CREATE TABLE points (
id_point INT NOT NULL AUTO_INCREMENT,
point_value INT NOT NULL,
PRIMARY KEY (id_point)
);
CREATE TABLE companies_faces_points (
id_company INT NOT NULL,
id_face INT NOT NULL,
id_point INT NOT NULL,
PRIMARY KEY (id_company,id_face,id_point),
FOREIGN KEY (id_company) REFERENCES companies(id_company),
FOREIGN KEY (id_face) REFERENCES faces(id_face),
FOREIGN KEY (id_point) REFERENCES points(id_point)
);
Me genero el bundle con el siguiente comando en cmd:
php bin/console doctrine:gernerate:bundle ---namespace=BackendBundle --format=yml
Y me genera el bundle sin problemas. Apartir de aqui es cuando se peresenta mi problema.
Ahora creo el mapping con el siguiente comando:
php bin/console doctrine:mapping:import BackendBundle
Me genera el mapa de las tablas:
- companies
- points
- faces
Pero no me genera el mapa de la tabla:
- companies_faces_points
Por la terminal no me devuleve ningún tipo de error.
Información buscada
He estado buscando sin ningún resultado, y lo que he encontrado es que permite el user de claves compuestas pero no se porque no me gerana el mapeo de dicha tabla.
Tipo de solución
Busco una solución la cual me permita mantener la clave compuesta.
Si mientras usted leyó este post se le ocurrio la idea de crear un id gérico y dejar las otras dos campos como foregin key. No lo considerare como una solución valida.
Novedades
Depués de conseguir que creara la entidad de la tabla con composite key me devuelve el siguiente erro:
No identifier/primary key specified for Entity "BackendBundle\Entity\CompaniesFacesPoints". Every Entity must have an identifier/primary key.
Código de la entity:
<?php
namespace BackendBundle\Entity;
/**
* CompaniesFacesPoints
*/
class CompaniesFacesPoints
{
/**
* @var \BackendBundle\Entity\Companies
*/
private $idCompany;
/**
* @var \BackendBundle\Entity\Faces
*/
private $idFace;
/**
* @var \BackendBundle\Entity\Points
*/
private $idPoint;
/**
* Set idCompany
*
* @param \BackendBundle\Entity\Companies $idCompany
*
* @return CompaniesFacesPoints
*/
public function setIdCompany(\BackendBundle\Entity\Companies $idCompany = null)
{
$this->idCompany = $idCompany;
return $this;
}
/**
* Get idCompany
*
* @return \BackendBundle\Entity\Companies
*/
public function getIdCompany()
{
return $this->idCompany;
}
/**
* Set idFace
*
* @param \BackendBundle\Entity\Faces $idFace
*
* @return CompaniesFacesPoints
*/
public function setIdFace(\BackendBundle\Entity\Faces $idFace = null)
{
$this->idFace = $idFace;
return $this;
}
/**
* Get idFace
*
* @return \BackendBundle\Entity\Faces
*/
public function getIdFace()
{
return $this->idFace;
}
/**
* Set idPoint
*
* @param \BackendBundle\Entity\Points $idPoint
*
* @return CompaniesFacesPoints
*/
public function setIdPoint(\BackendBundle\Entity\Points $idPoint = null)
{
$this->idPoint = $idPoint;
return $this;
}
/**
* Get idPoint
*
* @return \BackendBundle\Entity\Points
*/
public function getIdPoint()
{
return $this->idPoint;
}
}
roducir el código aquí
Novedades sobre las novedades
El error No identifier/primary key specified viene porque al usar el generador automático no genero los id en el siguiente yml:
CompaniesFacesPoints
BackendBundle\Entity\CompaniesFacesPoints:
type: entity
table: companies_faces_points
indexes:
id_face:
columns:
- id_face
id_point:
columns:
- id_point
IDX_11231BC89122A03F:
columns:
- id_company
id: {}
oneToOne:
idCompany:
targetEntity: Companies
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
id_company:
referencedColumnName: id_company
orphanRemoval: false
idFace:
targetEntity: Faces
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
id_face:
referencedColumnName: id_face
orphanRemoval: false
idPoint:
targetEntity: Points
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
id_point:
referencedColumnName: id_point
orphanRemoval: false
lifecycleCallbacks: { }
¿Como he de rellenar los ids dato este caso? He intentado ponerlos copaindo el código de otro yml y cambiando las referencias pero me salta el siguiente error al hacer eso:
Property "idCompany" in "BackendBundle\Entity\CompaniesFacesPoints" was already declared, but it must be declared only once