Hi there I’m having trouble establishing relations in my lifecycle methods. I really don’t know how to establish these relationships which causes internal server errors when creating these in the admin panel.
I have two collection types the message and message-status as described in the code snippets shared in the files of the message-status schema, message status and message lifecycle. I would really like some help with connecting relationships because when I create the message in the message collection with these relationships in the admin panel it raises an internal server error.
This topic has been created from a Discord post (1268538705891688499) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord
Can you share the error message? Should be displayed in the terminal when you run strapi develop
This is the error message I get when I do try creating the message in the admin panel
This is the message I get after entering the message in the admin panel
I don’t necessarily see something odd in the definition of the where object. But I do am a little but puzzled by this loop. If I understand it correctly, it will end up in an infinite loop when there are less then 100 (BATCH_SIZE) messages from users whose id is not equal to that of result.sender.id
I also don’t understand where t0 comes from.
This page should explain how to extend find request with relational field types;
But based on the error message, I don’t feel like that is the problem you are facing.
Is there a reason that you’d like to use strapi.db over strapi’s entityService? That being said. I don’t know if strapi.db is also “protected” by the users & permissions plugin. Maybe that could be part of the problem?
I have removed the batch size logic and modified it to just simply selecting the users and mapping through them.
In this guide they show me how to manage relationships however I cannot see how it applies.
I think the error is related to this but I
That documentation is suited for the entityService
Looking up tutorials this guy explains it better
When you look into the code I’m interacting with the service direct in my afterCreate lifecycle method.
It finally worked. The error was with the strapi query for the user which was returning was causing the error because I was accessing the sender in the result of the lifecycle method yet the sender was not defined since the result returned is not populated by default.