Creating Morph Relations

System Information
  • Strapi Version: 4.9.1
  • Database: SQLite or PostgreSQL

I want to create a table just like the media that can be a polymorphic field in any table. Something like comment. I tried to emulate the way that Strapi handles the file collection’s related field but I’ve encountered a lot of errors. The most recent one is:

[2023-08-17 13:39:57.717] error: data[key] is not iterable
[2023-08-17 13:39:57.718] debug: error: DATA[KEY]_IS_NOT_ITERABLE
[2023-08-17 13:39:57.719] error: data[key] is not iterable
TypeError: data[key] is not iterable
    at handleMorphRelation (C:\Users\Luay\Documents\Childcare\backend\node_modules\@strapi\utils\lib\sanitize\visitors\remove-restricted-relations.js:23:33)
    at C:\Users\Luay\Documents\Childcare\backend\node_modules\@strapi\utils\lib\sanitize\visitors\remove-restricted-relations.js:56:13      
    at Array.traverseEntity (C:\Users\Luay\Documents\Childcare\backend\node_modules\@strapi\utils\lib\traverse-entity.js:76:11)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async C:\Users\Luay\Documents\Childcare\backend\node_modules\@strapi\utils\lib\async.js:10:13
    at async Object.sanitizeOutput [as output] (C:\Users\Luay\Documents\Childcare\backend\node_modules\@strapi\utils\lib\sanitize\index.js:44:18)
    at async Object.find (C:\Users\Luay\Documents\Childcare\backend\node_modules\@strapi\strapi\lib\core-api\controller\collection-type.js:24:32)
    at async returnBodyMiddleware (C:\Users\Luay\Documents\Childcare\backend\node_modules\@strapi\strapi\lib\services\server\compose-endpoint.js:52:18)
    at async policiesMiddleware (C:\Users\Luay\Documents\Childcare\backend\node_modules\@strapi\strapi\lib\services\server\policy.js:24:5)  
    at async serve (C:\Users\Luay\Documents\Childcare\backend\node_modules\koa-static\index.js:59:5)

Is there an official way to implement morphOne and morphMany relations?

1 Like

Have you found any solutions?