Good, I have an action in my controller that what it does is collect the records of the entity Address and make a Join with the City entity to obtain the name of the city (City entity field name), for this I have this code that works but I returned the json in this format in two levels, I would like to receive all the information at the same level
/**
* @param Request $request
* @Route("/find/", name="admin_Address_find")
* @return JsonResponse
*/
public function findShopAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$ap = $qb->select('a','c.name as nameCity')
->from('AppBundle\Entity\Address', 'a')
->innerJoin('AppBundle\Entity\City','c','WITH','a.city = c.id')
->getQuery()
->getArrayResult();
return new JsonResponse($ap);
}
The resulting code of the JSOn is this
[{"0": {"id": 3, "addressName": "9", "numberAddress": "9", "phone": 9, "nameCity": "BCN"}, {"0": {"id": 4, "addressName": "4", "numberAddress": "4", "phone": null, "nameCity": "BCN"}, {"0": {"id": 34, "addressName": "address 2", "numberAddress": "47", "phone": 973112233, "nameCity": "BCN"}, {"0": {"id": 35, "addressName": "address", "numberAddress": "1", "phone": 1, "nameCity": "BCN"}]