Sorting by count of records of connected table

Notice: This thread is very old.
Generous Backer | 236


a have tables Article and Users M:N connected by property article_like. It says, who liked an article. Also there is table Tag, M:N again, connected to articles table.

In the template linked below, I have a tag. By this tag, a list of articles is listed. It works well in this state. But I would like to have this list sorted by count of likes.…efault.latte#L24

How can I achieve that? Is it even possible? I think I was close with ->order('COUNT(article(article_like)'), but the error No reference found for $article->related(users). says this is not right.


You can find Czech version here…jene-tabulky#…

Last edited by medhi (2015-01-26 17:50)