I have an entity/table of employees. Somewhere in database (in many places actually) this entity can be used in relations/foreign keys.

The task is simple: if the employee is used somewhere, I shouldn't show "delete" button, otherwise employee can be deleted.

The question is not about how to achieve deleting (cascade/restrict foreign keys), it's more about how to return to client side information about "if the employee is used somewhere".

I use Laravel's ORM, and the thing is it feels quite clumsy to just to join / try to find employe in many places in DB manually (like, do many joins and wheres in order to try to find out if employee is used or not).

Is there any common solution for this? Even if I do it like I described it's going to be cumbersome. Or I should add a column like "is_taken" and handle the value programmatically on the server side?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.