Is it possible to subscribe to a creation of a model?
So I have a ticket model, and I want to execute an handler when a new model is being created, the thing is, if i subscribe to a middleware or $extend, I need to specify from where exactly i create that model, but the thing is, there are many options via nested queries to do that, e.g.:
How can I do that?
And a follow up question, whenever I create a new ticket, I also want to execute something else (push a message broker event), so if one of them fail i want to fallback the query, i.e. i need a $transaction. How can I do that?
Pseudo code of what I want:
4 Replies
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into
#ask-ai
for a quick spin!Hey @tort6334 👋
Did you had a look at this extension?
https://github.com/olivierwilkinson/prisma-extension-nested-operations
GitHub
GitHub - olivierwilkinson/prisma-extension-nested-operations: Utils...
Utils for creating Prisma client extensions with nested operations - olivierwilkinson/prisma-extension-nested-operations
Thanks @Nurul (Prisma) ! ❤️ yeah that one will do the trick. But a thing to probably notice is that it's CPU and not IO to look through all nested objects. But I guess it has minor effect because most queries not that deep?
Yes, I don't expect it to have any major effect. Please feel free to submit a bug report in case you observe any major issues.