dql query error class is not defined
Refer to the entities in your DQL by their namespaces, i.e. AppBundle:Article
and AppBundle:User
, that should make the error go away.
Use association mapping (old docs) instead of authorId
in your entity, this way Doctrine will take care of loading the author:
/** * @ORM\ManyToOne(targetEntity="User") * @ORM\JoinColumn(name="author_id", referencedColumnName="id") **/ private $author;public function getAuthor() { return $this->author;}public function setAuthor($author) { $this->author = $author;}
Your query would be reduced to:
SELECT a FROM AppBundle:Article a ORDER BY a.creationDate DESC
Once you have loaded an article, you can conveniently access the author:
...$author = $article->getAuthor();