You need to use your person's FK definitions to get the PK field (property).
Example:
I have entities:
documentoDocumento (an object with relationships between documents)
documento (document information with document_Type_Id FK)
documentTipo (link object with document_type_id → (my goal !!))
In documentDocument:
/** * @var Documento * * @ManyToOne(targetEntity="Documento") * @JoinColumns({ * @JoinColumn(name="documento2_id", referencedColumnName="id") * }) */ private $documento2;
In the document object:
/** * @var DocumentoTipo * * @ManyToOne(targetEntity="DocumentoTipo") * @JoinColumns({ * @JoinColumn(name="documento_tipo_id", referencedColumnName="id") * }) */ private $documentoTipo;
TABLE
[DocumentoDocumento] -- table with some type of relations between documents * id pk - documento1_id fk - documento2_id fk [Documento] *id pk -documento_tipo fk -- type of document - blablabla [DocumentoTipo] *id pk -tipo -- type description ************************
I want to select data from DocumentoDocumento and show tipo from DocumentoTipo.
This returns an error:
$qb3 = $this->_em->createQueryBuilder(); $qb3->select('dd.id, dd.documento, d2.contenidoTipo') ->from('Mnc\Entity\DocumentoDocumento', 'dd') // select from DocumentoDocumento ->innerJoin('dd.documento2','d2' ); // join to 'd2'
but with:
$qb3 = $this->_em->createQueryBuilder(); $qb3->select('dd.id, dd.documento, dt2.tipo documentoTipo, dt2.id documentoTipoId') ->from('Mnc\Entity\DocumentoDocumento', 'dd') // select from DocumentoDocumento ->innerJoin('dd.documento2','d2' ) // join to 'd2' ->innerJoin('d2.documentoTipo', 'dt2'); // join FK in d2 to dt2
I get dt2.id with an alias of 'documentoTipoId'.
source share