Member-only story

You need to stop updating your Entities in Symfony and start using the Query Builder. Here’s why.

David Garcia
Stackademic
Published in
5 min readJun 3, 2024
Symfony / Doctrine — database encryption | by Dariusz Włodarczyk | Nerd For Tech | Medium

Today, I want to tell you about a real-world problem I encountered some years ago. Due to the Non-Disclosure Agreement I signed, I won’t mention if this was a problem working for an agency or a product company, but it could affect both.

You can follow up on the “Race Condition” problem I exposed in this article by reading the next one.

One of the most convenient practices when working with Symfony (or any other framework; let’s face this reality) is the ability to auto-inject a specific Entity into your Controller.

This is achieved by mapping its primary ID/UUID field into your URLs, a feature that greatly simplifies your coding process.

// src/Controller/BlogPostController.php

namespace App\Controller;

use App\Entity\BlogPost;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Attribute\Route;

class BlogPostController extends AbstractController
{
#[Route(path: '/blog/post/{uuid}', methods: ['GET'])]
public function __invoke(
BlogPost $blogPost,
): Response
{
// ...
}
}

While using this approach to retrieve an existing Entity from the Repository can be very handy, it’s important to note that it’s also

Published in Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.

Written by David Garcia

Senior Software Engineer, Backend, NodeJS & Symfony developer, workaholic, passionate for new technologies and OSS contributor. https://linktr.ee/davidgarciacat

No responses yet

Write a response

Good insights