Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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