Get data from tables linked with HABTM relation

Hi everybody,

at first please let me start with a brief description:

I have a system that manages Rulings issued by the official authority. Each Subject, who is holder of permission or other Ruling, has a Workplace.

Subjects and Workplaces have at least one contact person (one person can belong to many Subjects/Workplaces and vice versa) and each Rulings has one Supervisor. Supervisor is a Person defined in People Table using the alias.

Imagine, that we have a Subject with contact person “John”, Workplace with contact parson “Marry” and Ruling valid for Subject and Workplace with Supervisor( i.e. specially trained person) “Donald”.

In other words, Donald is related to Subject and Workplace only on the base of Ruling.

When I bake View e.g. for my Subjects, a specific section called “Related people” is created. This section will list “John” in my case.

Related people

How can I list all Supervisors on a View page related to Subject or Workplace with specific id. I.e. I would like to add following related data on the Subject View page:

Related Supervisors
1 “Donald”
etc. …

Thank you in advance!

Here is the solution: