Reputation: 22956
I have two tables, one has a foreign key to the other. For ease of use let's say I have a table named 'Boy' with a foreign key for iceCreamId to a table called 'IceCream'.
In hasura the only way I can see how to create an entry in IceCream when I insert into boy is through the query.
Is there a way I can trigger a default IceCream insert when a 'Boy' is inserted through the backend? Don't like the frontend being relied on to do this.
Upvotes: 1
Views: 866
Reputation: 1033
You can simply use Hasura event triggers
Hasura can be used to create event triggers on tables in the Postgres database. Event triggers reliably capture events on specified tables and invoke webhooks to carry out any custom logic.
so, in your case, you can set up a simple event trigger on the create/update of the Boy table, you can then create the IceCream row in your webhook.
The one thing cooler about event triggers is that you can manually invoke/retry the same operation in case of failure!
for more info: Hasura Event triggers
Upvotes: 0
Reputation: 21157
Hasura builds on top of the functionality of your database and works best when you embrace all the functionality that the underlying DB has to offer.
This can easily be accomplished using a Database Trigger (I am assuming you're using Postgres here)
Triggers allow you to run additional logic in the backend either for validation or to do create, update, delete etc when records are updated, deleted or created
Upvotes: 1