Invalid PathExpression value when trying to execute a request

I do not know what else I can try.

I get this error:

[Semantic error] row 0, column 10 next to 'idEntrada FROM': Error: invalid path expression. There must be a StateFieldPathExpression expression.

This is my request:

$query=$em->createQuery("SELECT mp.idEntrada FROM PAVPrimerAvisoBundle:ModeradoPor mp WHERE mp.idUsuario = $userId"); 

And this is my essence:

 class ModeradoPor { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var integer * * @ORM\ManyToOne(targetEntity="User") * @ORM\JoinColumn(name="user", referencedColumnName="id") */ private $idUsuario; /** * @var integer * * @ORM\ManyToOne(targetEntity="Entrada") * @ORM\JoinColumn(name="idEntrada", referencedColumnName="id") */ private $idEntrada; /** * @var integer * * @ORM\Column(name="votacio", type="integer") */ private $votacio; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set idUsuario * * @param integer $idUsuario * @return ModeradoPor */ public function setIdUsuario($idUsuario) { $this->idUsuario = $idUsuario; return $this; } /** * Get idUsuario * * @return integer */ public function getIdUsuario() { return $this->idUsuario; } /** * Set idEntrada * * @param integer $idEntrada */ public function setIdEntrada($idEntrada) { $this->idEntrada = $idEntrada; } /** * Get idEntrada * * @return integer */ public function getIdEntrada() { return $this->idEntrada; } /** * Set votacio * * @param integer $votacio */ public function setVotacio($votacio) { $this->votacio = $votacio; } /** * Get votacio * * @return integer */ public function getVotacio() { return $this->votacio; } 

If I make this request:

 $query=$em->createQuery("SELECT mp FROM PAVPrimerAvisoBundle:ModeradoPor mp WHERE mp.idUsuario = $userId"); 

or

 $query=$em->createQuery("SELECT mp.id FROM PAVPrimerAvisoBundle:ModeradoPor mp WHERE mp.idUsuario = $userId"); 

works great. It is simple with mp.idEntrada.

Is there a typo in my Entity?

Edit: also happens with mp.idUsuario.

EDIT: For example, I dump a mysql query and it is shown like this (when SELECT mp )

 SELECT m0_.id AS id0, m0_.votacio AS votacio1, m0_.user AS user2, m0_.entrada_id AS entrada_id3 FROM ModeradoPor m0_ WHERE m0_.user = 5 

I can also do SELECT mp.id

But never mp.idEntrada / mp.idUser

+4
source share
2 answers
 SELECT IDENTITY (mp.entrada)FROM PAVPrimerAvisoBundle:ModeradoPor mp WHERE mp.idUsuario = $userId 

This solved the problem. Pay attention to "IDENTITY"

+8
source

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'.

+1
source

All Articles