Retrieve several models

Hi ! I would like to retrieve sereval models in one call but I can’t by if there is a method to do so.

Something like that :

const ids = [1, 2, 3];
sports.findByPk(ids).then(sports => {
    // do something
})

Is there a way to do this ?

Hello @Aurelien and welcome to the ForestAdmin community.

findByPk will expect its parameter to be the (unique) identifier of an object in database.

To fetch multiple items, you can do something like:

sports.findAll({
  where: {
    id: ids,
  },
});

You can find more info there https://stackoverflow.com/questions/24920427/sequelize-error-when-using-where-and-in-on-a-subarray or in the Sequelize documentation here https://sequelize.org/

Hope this helps.

2 Likes

That is perfect, thanks a lot !

1 Like