Avoid Doctrine to return full related entity
17:50 13 Feb 2021

I am new in Symfony and I am trying to get all the records from my content table. It works but it also returns all the fields from the related entity.

$content = $this->contentRepository->findAll();

And here is what I get:

[{
    "id": 2,
    "field1": "xx",
    "field2": "xx",
    "field3": 22,
    "field4": {"id":1, "field1":"xx", ...},
    ....
},...]

On field4 I would like to get only the id as a value, instead of the whole object. Like if I were doing a SQL. Reading from other places I found about lazy_loading but it doesn't seem to work.

php sql symfony doctrine