我有一个模型(产品),有一个图像列表。如何获取文件的路径?
const data = await Category
.forge()
.orderBy('order', 'DESC')
.fetchAll({
withRelated: [
'products',
'products.images',
]
})
使用上面的查询我得到这个'图像'数据:
[{
"id": 6,
"upload_file_id": 6,
"related_id": 2,
"related_type": "products",
"field": "images"
}]
Strappy v3.0.0-alpha .19,Book Bookshelf(OFC)
到目前为止我能找到的最好方法是使用upload
插件来获取数据:
for (const category of categories) {
for (const product of category.products) {
const files = await strapi.plugins.upload.models.file
.where('id', 'IN', product.images.map(i => i.upload_file_id))
.fetchAll();
product.images = files.models.map(f => f.attributes)
}
}
希望有更好的选择一次获取所有数据