The below code works as intended, i.e) gets the train details from trains table. If status is not present in trains table, it then looks for status from train_statuses table