[details=“System Information”]
- Strapi Version: V4.0.2
- Operating System: mac OS Monterey
- Database: PG
- Node Version: 16.13.1
- NPM Version:
- Yarn Version: 1.22.17
I have 2 entities named SampleFileExtensions
and SampleFileVariants
having relationship one to many. For example, MP4 is an extension and it can have multiple variants like Large, Medium, Small. So my function for getting extension look like this:
async findOne(ctx) {
const { slug } = ctx.params;
const entity = await strapi.db
.query("api::sample-file-extension.sample-file-extension")
.findOne({
where: { slug: slug },
populate: { variants: true },
});
const sanitizedEntity = await this.sanitizeOutput(entity, ctx);
return { data: entity };
// return this.transformResponse(sanitizedEntity);
},
But problem is transforming an entity for unified response loose related object. see the screenshots below: (this.transformResponse(sanitizedEntity)
response with transformation
response without transformation
My schema.json look like this:
{
"kind": "collectionType",
"collectionName": "sample_file_extensions",
"info": {
"singularName": "sample-file-extension",
"pluralName": "sample-file-extensions",
"displayName": "SampleFileExtension"
},
"options": {
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"name": {
"type": "string"
},
"info": {
"type": "string"
},
"details": {
"type": "richtext"
},
"slug": {
"type": "string"
},
"variants": {
"type": "relation",
"relation": "oneToMany",
"target": "api::sample-file-variant.sample-file-variant",
"mappedBy": "extension"
},
"type": {
"type": "relation",
"relation": "manyToOne",
"target": "api::sample-file-type.sample-file-type",
"inversedBy": "extensions"
}
}
}