Sort data by relative model count

I have a comment table:

Comment Table : | id | post_id | ...... |

Post Table: | id | catalog_id | ...... |

Catalog Table: | id | post_id |

so, in my Post Model:


in my Comment Model:


what I want to implement is get the most comment Catalog NOT most comment Post.


paginator = new \Phalcon\Paginator\Adapter\Model([
            'data'       => $data,
            'limit'      => $this->recordPerPage,
            'page'       => $page,

But I really don't know how sort the data by the sum of another table in phalcon.

Can Phalcon can implement something like that?

I guess you need to have your data sorted before passing for pagination, Create a custom query to retrieve Posts by the count of Comments and then pass the retrieved data to paginator

Or i didn't get you well.