After taking a look at the SQL queries, I've just figured out Api platform was requesting useless queries from object not displayed in the JSON.
How to reproduce:
In the DB:
DROP DATABASE IF EXISTS apibug;
CREATE DATABASE apibug;
Then:
git clone https://github.com/Softizy/api-bug
cd api-bug;
./bin/console doctrine:schema:create
./bin/console server:start
curl -X POST "http://127.0.0.1:8000/api/mums" -H "accept: application/ld+json" -H "Content-Type: application/ld+json" -d "{ \"mumId\": \"0test0\"}"
curl -X GET "http://127.0.0.1:8000/api/mums" -H "accept: application/ld+json" -H "Content-Type: application/ld+json"
{
"@context":"\/api\/contexts\/Mums",
"@id":"\/api\/mums",
"@type":"hydra:Collection",
"hydra:member":[
{
"@id":"\/api\/mums\/0test0",
"@type":"Mums",
"mumId":"0test0"
}
],
"hydra:totalItems":1
}
In the doctrine debug, you'll see:
cat ./var/log/dev.log
[2019-06-17 19:23:49] doctrine.DEBUG: SELECT m0_.mum_id AS mum_id_0 FROM mums m0_ ORDER BY m0_.mum_id ASC LIMIT 10 [] []
[2019-06-17 19:23:49] doctrine.DEBUG: SELECT t0.latitude AS latitude_1, t0.longitude AS longitude_2, t0.mum_id AS mum_id_3 FROM mum_locations t0 WHERE t0.mum_id = ? ["0test0"] []
[2019-06-17 19:23:49] doctrine.DEBUG: SELECT count(m0_.mum_id) AS sclr_0 FROM mums m0_ [] []
The query on mum_locations seems to be useless, it shouldn't be hydrated by getOneOrNullResult
Am I missing something?
After taking a look at the SQL queries, I've just figured out Api platform was requesting useless queries from object not displayed in the JSON.
How to reproduce:
In the DB:
Then:
{ "@context":"\/api\/contexts\/Mums", "@id":"\/api\/mums", "@type":"hydra:Collection", "hydra:member":[ { "@id":"\/api\/mums\/0test0", "@type":"Mums", "mumId":"0test0" } ], "hydra:totalItems":1 }In the doctrine debug, you'll see:
The query on mum_locations seems to be useless, it shouldn't be hydrated by getOneOrNullResult
Am I missing something?