We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

help with Query builder, order by datetime descending

so I have this line here:

Posts::query()->order('posts.postTime DESC')->limit(10)->execute();

which should be the same as this from mySQL?

SELECT * FROM posts ORDER BY posts.postTime DESC LIMIT 0 , 10

But it doesn't seem to order it by the timestamp at all



1.7k

found the solution:

$parameters = $this->persistent->parameters; if (!is_array($parameters)) { $parameters = array(); } $parameters["order"] = "postTime DESC";// added DESC to this line here

    $posts = Posts::find($parameters);

    $paginator = new Paginator(array(
        "data" => $posts,
        "limit"=> 10,
        "page" => $numberPage