-
So I have a set of API routes that correspond to related data like so:
The employee has a foreign key to team and team has a foreign key to company. Obviously I could use useSWR to fetch all the data at once like so:
My idea is to have a master detail UI where I have a list of companies. I can click a single company to get a list of teams. I can click a team to get a list of employees. However, what should happen if I delete a team with id 2? I'm just confused on how to handle mutations such that related cascade deletes. Furthermore if a local component usesSWR on /api/team/2 for example, wouldn't I have to mutate that unique key as well? What's the best way to handle relational data? At the moment I'm using Redux-ORM but that's probably overkill. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
You can trigger a revalidation of all the keys you know/suspect have the deleted item, if you delete the team with id 2 you may want to do |
Beta Was this translation helpful? Give feedback.
-
Is there a more effective way to structure the api to work better with useSWR? |
Beta Was this translation helpful? Give feedback.
You can trigger a revalidation of all the keys you know/suspect have the deleted item, if you delete the team with id 2 you may want to do
mutate('/api/team')
andmutate('/api/team/2')
to revalidate both.