strapi-community/strapi-plugin-transformer

Feature request: flatten populated data

cortopy opened this issue ยท 6 comments

In Strapi v4* (and already using strapi-plugin-transformer) when populating fields, the joined entity comes back flatten as expected ๐Ÿ‘

However, they have also added a data field, so you get something like:

{
  image: {
   data: {
      id: 1,
      //...
    }
 }
}

it would be great if, like with the attributes field, the response is flattened to:

{
  image: {
      id: 1,
      //...
 }
}

not sure how complex this would be but just a thought

This is related to #12 , I provided a similar situation there as well. In version 1.0.1 the data was flattened, but with 1.0.3 it is not. I have checked with Strapi version 4.0.7 and 4.1.1, and the Strapi version doesn't make a difference.

hello @cortopy and @adriaanh,

The data key not being in the response was a bug in the transformer algorithm, per the removeAttribute example it should have been left in when the attributes key was removed. This was fixed in 1.0.3 as part of #7 (thought i mentioned it, it has since been added as a note on the PR).

It looks like their is some interest in adding an additional setting to revert the behavior to not include data. I will look into adding this in for the next release. As it changes API for the user it will be a major release most likely.

Option to also remove data key would be great :)

This would then match the format that you are using in the slugify plugin as well. Right now there is inconsistency between these two plugins.

Did this quickly if it can serve anyone or if you want to use some of it @ComfortablyCoding
#15

This will be in the next release

This feature has been added in v2.0.0