Deleting multiple rows - nesting

I am using the delete multiple rows feature for the first time (yup, didn’t realize it had appeared!).

My question is: If the relation is empty, will the action be forbidden, despite subsequent steps being possible? See screenshot.

I want to delete the parent row in a table and all the related children rows. So in step 1 I delete the multiple child rows using the relation. Then in step 2 I delete the parent row.

However, I 'm concerned that if the parent has no children then the action will not be allowed and the parent will not be deleted. Or will Glide just skip the first step since it is an empty relation and execute the second?

I have noticed that sometimes buttons are not visible when the corresponding actions are not possible.

1 Like

The way to do this is as follows:

  • Delete Row (children, via relation)
  • Wait for condition (relation is empty)
  • Delete Row (parent)

The wait is important, otherwise you risk the parent being deleted before all children are gone (and hence breaking the relation), leaving one or more orphans.

As to what will happen if the initial state of the relation is empty, I’m not sure. But it will be easy enough to test that to find out.

Worst case, you would just need a condition at the start of the action - one branch to deal with each initial state of the relation.

3 Likes

Thanks. Top tips.

I have a similar scenario where I Set Column values in a couple of tables through relations. Those actions are among others that need to run regardless if the relations are empty or not. If those relations are empty, the entire button disappears.

Agree. I think the logic should be to skip a step in the action when the relation is empty, not invalidate the whole action.

I have used Darren’s tip with the if else branch for the childless scenario and a wait for condition (relation becomes empty before deleting the parent) for the other, with a 3 second time out. I hope that works!

1 Like

Nice didnt know we could delete multiple rows now!

1 Like

This has actually been possible for about a year and a half.

2 Likes

Hahaha, never really had a use case. Dont know what you dont use! :rofl:

4 Likes