'Strapi deep sort

Let's say I have modelA with a ForeignKey on modelB.

In api/modelA/services/modelA.js, I can define:

// [...]
module.exports = {
  /**
   * Promise to fetch all records
   *
   * @return {Promise}
   */
  find (params, populate) {
    params = {
      ...params,

      _sort: 'field_from_model_a:DESC,other_field_model_a:ASC'
    }
    populate = [
      'modelB'
    ]
    return strapi.query('post').find(params, populate)
  },
// [...]

This allows me to sort my query and I can also filter deep relations when using

curl -X GET "http://localhost:1337/modelA?modelB.field_from_model_b=example_value

But I can't find how to sort on modelB.some_field.

If I write _sort: 'modelB.field_model_b:ASC', I get an error saying: missing FROM-clause entry for table "modelB"



Solution 1:[1]

deep sorting is available from Strapi v3.4.2 onwards have a look Strapi release v3.4.2

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lin