I have these two models with M2M relation
portfolio
portfolio-types
Inside portfolio
there's a media field which uses s3
at the moment called feature_image
.
This media field contains lots of other attributes and the only attributes I need in return are url, width, height
I am trying to query from portfolio-types
to populate portfolio
and inside portfolio, I only want to show the three fields as mentioned above url, width, height
but I cannot see to make it work.
By the way, I already read some other posts such as
Strapi CMS: Fetch Nested Content
https://github.com/strapi/strapi/issues/4996
but none of them seem to work
sample of what I tried
await strapi.query('portfolio-type').model
.findOne(query)
.select('name')
.populate([{
path: 'portfolios',
select: 'title',
populate: {
path: 'upload',
select: 'url'
}
}]);
/* tried all these below */
.populate({
path: 'portfolios',
select: 'title',
populate: {
path: 'upload',
select: 'url'
}
});
.populate({
path: 'portfolios',
select: 'title',
populate: {
path: 'feature_image',
model: 'upload',
select: 'name'
}
});
.populate({
path: 'portfolios',
select: 'title feature_image.url', // gives collation error caused by mongo version 4.4 and above
});
I mighted a few other ways which I might forgot because I was finding results online and kept on trying until I really can't seem to make it work.
Thanks in advance for any help and advices.