I need to add a feature to my system, it's a stock control system.
The feature to be added is about the possibility to start chats in different models. I have Products, Sellers, ProductCollections and a lot of more objects and I need to start conversations within them.
So I thought about making a table with three polymorphic fields to make it fully reusable with any variants. This are the fields
sender_id
sender_type
topic_id
topic_type
receiver_id
receiver_type
And the proper fields to make the conversation possible (message, in_reply_of, etc...)
The sender and receiver needs to be polymorphic because a conversation could be made between SystemUsers and Customers.
Am I in the right way? Will this work in this way? Also I don't know how could I save the Chat entities.
If you want to set a chat for multiple sender, receiver and topics, I believe this relation is good to go.
Also, I was unable to to understand what you exactly mean by Chat entities but the below approach should clear out any doubts you might be having about this approach.
Below is how you can get things done!
Setting the Relations
Set the relations in the following manner
Creating A Chat
How to create a chat
Getting a chat
Note :- Please understand I haven't tested any of this... This is just a small example on how you can get things done.
Let me know if you face any issues understanding this.