mysql – Child, Parent and Grand-Parent relationship where a child may not necessary have a parent or a grand parent

Here, I have some problem representing a hostel-room-inmate entities.

First an inmate is given a hostel seat,

Then he is allotted a particular hostel,

Then he is allotted a room.

My approach is that the inmate table contains a parent-link to the room table, the room table contains a parent-link to the hostel table.

table hostel(id, name)
table room(id, hostel_id, room_no)
table inmate(id, room_id, name, etc)

But while at the stage of allotment, the inmate is first allotted a hostel, in which the room_id is to be left blank, thereby meaning that the inmate is not allotted a hostel room and so on…

How do I solve this problem please…

I wanted to use it in Laravel development environment

(NB: I have some idea of creating many-to-many relationship type by creating relationship table, but just asking if there’s better approach than this.)