Full Version: GenDoc: can't get to related record tree
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have this in a gendoc template I use on an invoice:
{foreach MyModule}
{foreach CobroPago}
{CobroPago.reference}        € {CobroPago.amount}
Where 'MyModule' is a custom module that has is related to the invoice and the CobroPago (Payment) records are in turn related to 'MyModule'. For some reason I can show fields from 'MyModule' but not from the Payment (CobroPago) records. What am I doing wrong?
Looks correct to me. I suppose the relation MyModule > CobroPago is a normal get_related_list?
No, in fact there are two custom 'get_related_...' functions I built to create custom related lists. I was afraid that would be the issue. How could I get around this?
that is probably the issue, depending on how you return the SQL probably.

first try using the direct document generation (accessing GenDoc module directly) with Debug active, to see if you can find some information about what it is doing on that foreach
Is there some documentation on debugging gendoc templates? I'm not sure how to do it.
first, go to the module: index.php?module=evvtgendoc&action=index
that will take you to a direct generator where you pick the template, module, language and if you want to see debug information or not
then the fun is trying to understand what the outputmeans :-)
Cool, let me try that and report back here

OK so the debug didn't really do that much, other than provide me with some search terms to get me going in modules/evvtgendoc/compile.php. There I found this. I don't take this global variable assigment into account, nor do I adhere to query formatting of any kind in my related functions.

What I will try to do is check for the global '$GetRelatedList_ReturnOnlyQuery' in my custom related function and if so, call the 'regular' get_related_list function.
OK so this is pretty much solved. What you want to do when creating related list custom functions is fall back to the default SQL when 'SQL only' is required. Suppose your custom function looks something like:
PHP Code:
public function get_custom_related($id$tabid$rel_tabid$actions false) {
   global $adb;
   // Do some custom stuff

Then you would add a couple of fallback lines:
PHP Code:
public function get_custom_related($id$tabid$rel_tabid$actions false) {
   global $adb$GetRelatedList_ReturnOnlyQuery;

   if ($GetRelatedList_ReturnOnlyQuery) {
       return $this->get_dependents_list($id$tabid$rel_tabid);
   // Do some custom stuff

Where you would choose to fallback either on 'get_dependents_list' or 'get_related_list' based on what your custom function sees as a 'relation'.
Very interesting
Thanks for sharing!