'Key "image" for array with keys "id, title, artext, createdat, updatedat, position, status" does not exist
I'm working on Symfony 5.4, and have the following bugg
Key "image" for array with keys "id, title, status" does not exist.
Then I have two tables: Image and Article and need to post and arraw of Article, each article with his image.
Article Repository
public function findbyLast() {
$qb = $this->createQueryBuilder('a');
$qb->andWhere('a.status = 1');
$qb->orderBy('a.id', 'DESC');
$qb->setMaxResults( 10 );
return $qb->getQuery()->getArrayResult();
}
Article Controller
#[Route('/articles', name: 'articles')]
public function articles(ArticleRepository $articles): Response
{
return $this->render('main/articles.html.twig', [
'articles' => $articles->findbyLast() ,
]);
}
View on Twig
{% for x in articles %}
<a href="{{ path('app_article_show', {'id': x.id}) }}">
<h4>{{ x.title }}</h4>
{% if x.image %}
<img src="{{ asset('images/articles/'~x.image )}}" alt="{{ x.image.name }}" class="img-fluid row">
{% endif %}
{% endfor %}
I'v struggled on it, and don't know how to manage my repository to join and have that missing key.
Thanks for your help!!!
Solution 1:[1]
bugg resolved. I didn't make the difference between
getResult and getArrayResult in the repository. Get Result is rendering a list of objects and the other an array.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sany |
