Accessing grandparent fields in sub-panel


I have created three custom modules called MyLink, MyUser and MyAccount which are related as follows:
One to many relationship between Contact and MyLink
Many to one relationship between MyLink and MyUser
Many to one relationship between MyUser and MyAccount.

The reason for not having a many-to-many relationship directly between Contact and MyUser is that I need to store information about the relationship (i.e. a text field describing why that particular Contact is related to that particular MyUser).

When viewing a Contact, I can see the list of MyLink objects as a sub-panel. This shows the MyUser name field, which I can click on to go to the particular MyUser record. However, in that sub-panel, I would also like to display the name of the MyAccount that is linked to the MyUser, i.e. a grandparent field.

I have looked at the code in SugarBean.build_sub_queries_for_union() which builds the SQL query, but I really don’t understand how it works enough to see if it is possible to edit the vardefs file to define such a field.



There are ways to define some extra fields inside a relationship, without the need for that intermediate module (which is incorrect design).

It has to be done in PHP and it is a bit tricky to get it done, but here is a tutorial: