Sort by custom primary key

Expected behavior

I have a table Link which has a ManyToOne relationship avec a table Artist. The primary key of Artist if talentId, so I have link.artistTalentId = artist.talentId.

I want to sort my table Link by artistTalentId.

Actual behavior

What is the current behavior?

When I try to search by artistTalentId in my table Link in ForestAdmin, it adds the parameter ?sort=-artist.id to my url and I have a log telling me this column does not exists.

How can I configure the sort to use my custom primary key talentId?

This is my configuration in models :

Artists.hasMany(models.streamingLinks, {
      foreignKey: {
        name: 'artistTalentIdKey',
        field: 'artistTalentId',
      },
      target: {
        name: 'talentId',
      },
      as: 'artistStreamingLinks',
    });
StreamingLinks.belongsTo(models.artists, {
      foreignKey: {
        name: 'artistTalentIdKey',
        field: 'artistTalentId',
      },
      target: {
        name: 'talentId',
      },
      as: 'artist',
    });

Thank you very much!

Hi @Cyrielle_Willerval,

Sorry for the delayed reponse, but I took some time to setup a similar example :slight_smile:
In your case, the filter should be sort=-artist.talentId, am I correct ? If you manually edit the ?sort= with talentId instead of id, is everything working ?

The behavior I’m getting after setting this seems related to the “Reference field” set in your “Artist” model in forest. When I set “Reference field” to id, I’m getting sort=-artistTalent.id. If I change it to name, sort=-artistTalent.name.

Let me know if that helps

Hello @jeffladiray!

It solved my problem, thank you very much for your help!