I am developing a school management system, where the database has been simplified as given below:-
users(id, email, password);
students(id, user_id, roll_no, first_name, last_name, dob);
teachers(id, user_id, name, qualification);
guardians(id, user_id, name, phone, address);
From the database it is cleared that, we have a common login system for all kinds of profiles.
Problem: I can access a user credentials from a given profile such as students or teachers as there is a foreign key associated into the profile table. But to know the type of profiles associated to a user, I can not go down without searching each profile table.
What I have tried: I have created an intermediary table such as:-
user_profiles(id, user_id, table_name)
But this does not seems to be efficient as I need to code extra. Is their any way to associate users table to their respective profile table in the database layer itself?