How to remove children entities when a parent entity is removed

I have a lot of entities which share a single parent entity (through parent property), this allows me to hide and show them all at once (for example). I have multiple such parent entities

If I remove the parentEntity from the entity collection, the children still remains there. What I want is to remove them also.

Currently, before removing the desired parentEntity, I iterate over it’s _children array and remove each child one by one. I don’t like it

because ‘_children’ is private.

Can you suggest a correct approach?

The only correct solution right now is to iterate over all of the entities and remove them if their parent object matches the object you removed. We might expose _children as public in the future or make this use case easier in other ways, but for now that’s the only way.