Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Doctrine says Entity "has no field or association" used in a WHERE query, but it surely does

When I execute this query:

$array_ids_items = $this->em->createQuery(
    'SELECT i.id, i.id_alt
     FROM App\Entity\ItemComunicacao i
     WHERE i.id_tarefa IS NULL AND i.classificacao.abrir_tarefa = TRUE'
)->getArrayResult();

I get the error

"Class App\Entity\ItemComunicacao has no field or association named classificacao.abrir_tarefa"

But field ItemComunicacao.comunicacao surely exists:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

/**
 * @ORM\ManyToOne(targetEntity=ClassificacaoComunicacao::class)
 */
private ?ClassificacaoComunicacao $classificacao;

and so does field ClassificacaoComunicacao.abrir_tarefa:

/**
 * @ORM\Column(type="boolean", options={"default":false})
 */
private bool $abrir_tarefa = false;

So what’s the fuss about my query statement? If there is an error in it, error message is surely misguiding.

>Solution :

you forgot the join statement in your query.

You should add it to be able to request classificacao.abrir_tarefa.

It should be something like that (not tested)

$array_ids_items = $this->em->createQuery(
    'SELECT i.id, i.id_alt
     FROM App\Entity\ItemComunicacao i
     LEFT JOIN i.classificacao ic
     WHERE i.id_tarefa IS NULL AND ic.abrir_tarefa = TRUE'
)->getArrayResult();

hope it helped 🙂

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading