SalesTable - SalesLine - InventTable
For that case, we can apply the code as the following way.
void TreeJoinExample()
{
Query q;
QueryBuildDataSource qbdsSalesLine,
qbdsSalesTable,
qbdsInventTable;
;
q = new Query();
qbdsSalesLine = q.addDataSource(tableNum(SalesLine));
qbdsSalesTable = qbdsSalesLine.addDataSource(tableNum(SalesTable));
qbdsSalesTable.relations(false);
qbdsSalesTable.addLink(fieldNum(SalesLine, SalesId), fieldNum(SalesTable, SalesId));
qbdsSalesTable.fetchMode(queryFetchMode::One2One);
qbdsInventTable = qbdsSalesLine.addDataSource(tableNum(InventTable));
qbdsInventTable.relations(false);
qbdsInventTable.addLink(fieldNum(SalesLine, ItemId), fieldNum(InventTable, ItemId));
qbdsInventTable.fetchMode(queryFetchMode::One2One);
}