0

When loading my page, the toolbar tells me that I have 56 database queries while I only do one findBy().

picture database queries

I noticed that it comes from the twig part when I do "{{action.ticket.incidentRef}}". This is what produces all the database queries.

My controller :

/**
 * @Route("/", name="support_admin_action_index", methods="GET|POST")
 */
public function index(Request $request, TicketActionRepository $ticketActionRepository): Response
{
    $actions = $ticketActionRepository->findBy([], ['endDate' => 'DESC']);

    return $this->render('ticketing/admin/action/index.html.twig', [
        'actions' => $actions,
    ]);
}

My Entity :

/**
 * @ORM\Entity(repositoryClass="App\Repository\Ticketing\TicketActionRepository")
 */
class TicketAction
{
    ...
    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Ticketing\Ticket", inversedBy="actions")
     * @ORM\JoinColumn(name="ticket", referencedColumnName="id", nullable=false)
     */
    private $ticket;

    public function getTicket(): ?Ticket
    {
        return $this->ticket;
    }

    public function setTicket($ticket): ? TicketAction
    {
        $this->ticket = $ticket;

        return $this;
    }
    ...
}

How can I display in my twig {{action.ticket.incidentRef}} without doing all its queries?

skros3
  • 1
  • 1

0 Answers0