educative.io

I am not able to understand why we need more than 1 backref

I am not able to understand where is head_of_departmenet backref is used. Here is the attached image for reference. So there are 2 questions:

  1. In is_head_of column of the Employee class table, we are still using department.name, could we have used head_of_department.name?
  2. Why did we use head_of_department as a backref at all, when we already have a backref called department? does that mean we cannot repeat backrefs?

Hi @Ashutosh_Singh
The answers are as follows:

  1. No, we can’t use head_of_department.name because, head_of_department is not a table name.
  2. Secondly, there are employees which work in some departments and similarly, there will be some employees who are head of some department, that’s why both backrefs are used.