Actually no, count($programmers) it's the count of results shown in the page, and $pagerfanta->getNbResults() is the total number of results found in the database.
I had to add "->orderBy('programmer.id', 'ASC')" in findAllQueryBuilder for this to work. I don't understand why it's always given me programmers in a random order.
I agree - that's weird. But, we can easily debug and see what's going on. If you remove this orderBy line and refresh, you should be able to click the database icon in the web debug toolbar to go to the "Doctrine" tab on the profiler. On this page, you can see what the query looks like, to see if Doctrine is doing anything weird. It *should* simply be executing a query with *no* ORDER BY on it. If this is true, then it's actually your database that is returning things in a random order. In the profiler, you can click to get a "runnable" version of your query. If you run that directly on your database, you can see what happens: does it return in a random order, or ordered by id?
I fact, it's only on test mode. If i go to http://localhost:8000/api/programmers threw the navigator I have a normal request answer (from Programmer0 to Programmer9 with no ORDER BY). If I take the SQL and run it directly to my database, same good answer. It's only when I run the test command that the answer is in a random order. My normal and test database are build the same way.
I have tried to load fixtures in test database to see test environment in the navigator. And then, same answer as with the test command. A randomly ordered answer.
Huh, very interesting! Is your test database also in MySQL, or is it in Sqlite? I like how you debugged this: to load the fixtures in the test environment and then browse the site in the test environment. That's very puzzling :), as the same query should be used in both environments. Are you able to look at the test database to see if the data is loaded in the same way? I'm just trying to think of what could possibly be different between the test and normal databases...
Please, log in to vote for this comment
|
Share Comment
"Houston: no signs of life" Start the conversation!
This tutorial uses an older version of Symfony. The concepts of REST and serialization are still valid, but I recommend using API Platform in new Symfony apps.
6 Comments
Is the total from NBresults and Count() not the same thing?
Hey Dirk
Actually no,
count($programmers)it's the count of results shown in the page, and$pagerfanta->getNbResults()is the total number of results found in the database.Cheers!
I had to add "->orderBy('programmer.id', 'ASC')" in findAllQueryBuilder for this to work. I don't understand why it's always given me programmers in a random order.
Yo Kreviouss!
I agree - that's weird. But, we can easily debug and see what's going on. If you remove this orderBy line and refresh, you should be able to click the database icon in the web debug toolbar to go to the "Doctrine" tab on the profiler. On this page, you can see what the query looks like, to see if Doctrine is doing anything weird. It *should* simply be executing a query with *no* ORDER BY on it. If this is true, then it's actually your database that is returning things in a random order. In the profiler, you can click to get a "runnable" version of your query. If you run that directly on your database, you can see what happens: does it return in a random order, or ordered by id?
Let me know what you find out! Cheers!
I fact, it's only on test mode. If i go to http://localhost:8000/api/programmers threw the navigator I have a normal request answer (from Programmer0 to Programmer9 with no ORDER BY). If I take the SQL and run it directly to my database, same good answer.
It's only when I run the test command that the answer is in a random order.
My normal and test database are build the same way.
I have tried to load fixtures in test database to see test environment in the navigator. And then, same answer as with the test command. A randomly ordered answer.
So it seems to be a test environment issue...
(sorry for my bad French English ><)
Huh, very interesting! Is your test database also in MySQL, or is it in Sqlite? I like how you debugged this: to load the fixtures in the test environment and then browse the site in the test environment. That's very puzzling :), as the same query should be used in both environments. Are you able to look at the test database to see if the data is loaded in the same way? I'm just trying to think of what could possibly be different between the test and normal databases...
"Houston: no signs of life"
Start the conversation!