Problem: Entities (say Users) are showed in a paginated fashion in the UI. The UI also shows a checkbox against each entity, so that it is possible for the admin to multi-select users and delete them. It is quite natural that this entity is associated with many other entities via a foreign key relationship (say Purchase Orders created by him)
If a Purchase Order is associated with a certain user, user deletion will not be possible because of the foreign key violation. Similarly it is possible that User has relationship with many other such tables.
It would be preferable not to show the checkbox for deletion if the entity cannot be deleted. If such a check needs to be made, while constructing the user list page for each user row you need to query the dependant tables for possible relationships. This could be a very costly affair if there are many users.
What would be the suggested approach to solve this problem in a elegant fashion?