Multiple file in a file viewer

Oh sry was a bit lost haha, here is the response :

{"data":[{"type":"portfolio","id":"19","attributes":{"photos":"portfoliotitre011202111015101000100.jpeg,portfoliotitre111202111015101000100.jpeg,portfoliotitre211202111015101000100.jpeg,portfoliotitre311202111015101000100.jpeg","keywordInput":[],"id":19,"title":"titre","photographer":"test","keyword":null},"relationships":{"numero":{"data":{"type":"numero","id":"5"},"links":{"related":{"href":"/forest/portfolio/19/relationships/numero"}}}}},{"type":"portfolio","id":"16","attributes":{"photos":"portfolioheh010202117453401000100.jpeg","keywordInput":[],"id":16,"title":"heh","photographer":"hee","keyword":"jeje"},"relationships":{"numero":{"data":{"type":"numero","id":"4"},"links":{"related":{"href":"/forest/portfolio/16/relationships/numero"}}}}}],"included":[{"type":"numero","id":"5","attributes":{"id":5,"title":"Numero 2"}},{"type":"numero","id":"4","attributes":{"id":4,"title":"Test"}}]}

Okey this is what I thought, your photos is not an array but a simple string. You need to transform it to an array. So if it’s reeally a string in your database, just create a smart field that do a photos.split(',') should do the work and when doing a set you just need to do a .join(',').

Hope this helps you

I understand but is that working with mysql and a datatype.STRING ? I encouter this error …

image

Yes of course, you can do something like that

// forest/protfolio.js
collection('protfolio', {
  fields: [{
    field: 'photos_as_array'
    type: ['String'],
    get(portfolio) {
      return portfolio.photos ? portfolio.photos.split(',') : [];
    },
    set(portfolio, photos) {
      portfolio.photos = photos.join(',');
      return portfolios;
    },
  }],
})

This should do the trick

Great, It work perfectly ! Thank you very much !

1 Like