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

get related with order by (many-to-many)

I have simple many-to-many relation.
articles
tags
articlestags

I have smth like this

<?php foreach ($tag->articles as $article) :?>
<?= $article->title ?>
<?php endforeach;?>

What I need is to make it order by column article.release_date DESC



635
Accepted
answer

$tag->articles is an alias for $tag->getArticles($params) which is an alias for $tag->getRelated('articles', $params). $params takes the same params as the find() method, so you can do:

foreach ($tag->getArticles(['order' => 'release_date DESC']) as $article) {
  ....
}

or something like that