Question

I known that in sql statement the latest reply can be get by adding "order by created DESC limit 0,1"

But how can i get it using QueryBuilder? I have refered to the document of QueryBuilder . There is no limit() function.

Was it helpful?

Solution

Just use ->setMaxResults(1) to say "limit" with doctrine

And the doc': http://www.doctrine-project.org/docs/orm/2.1/en/reference/query-builder.html#limiting-the-result ^^

But in this case you should use ->getSingleResult() instide of ->getResult(), without using limit. (It's more appropriated !)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top