Sorting by count of records of connected table

4 years ago

medhi
Bronze Partner | 189
+
0
-

Hi,

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.

https://github.com/…efault.latte#L24

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

Thanks!

You can find Czech version here https://forum.nette.org/…jene-tabulky#…

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