I'd like to recreate this SQL code here, using QueryBuilder:
select Field1 from TableA
inner join TableB
on TableA.F1 = TableB.F1
inner join TableC
on TableC.F2 = TableA.F2 --note TableA again
This is the code I've generated so far:
QueryBuildDataSource dataSource;
QueryBuildDataSource dataSourceOMInternalOrg;
QueryBuildDataSource dataSource2;
str textDesc = "";
query = new Query();
dataSource = query.addDataSource(tableNum(LogisticsPostalAddress), "LogisticsPostalAddress");
dataSource.relations(false);
dataSource = dataSource.addDataSource(tableNum(LogisticsAddressCountryRegion), "LogisticsAddressCountryRegion");
dataSource.addLink(fieldNum(LogisticsAddressCountryRegion, CountryRegionId), fieldNum(LogisticsPostalAddress, CountryRegionId));
dataSource.joinMode(JoinMode::OuterJoin);
dataSource = dataSource.addDataSource(tableNum(DirPartyLocation), "DirPartyLocation");
dataSource.addLink(fieldNum(LogisticsPostalAddress, Location), fieldNum(DirPartyLocation, Location));
dataSource.joinMode(JoinMode::InnerJoin);
dataSource = dataSource.addDataSource(tableNum(DirPartyTable), "DirPartyTable");
dataSource.addLink(fieldNum(DirPartyLocation, Party), fieldNum(DirPartyTable, RecId));
dataSource.addLink(fieldNum(DirPartyLocation, Location), fieldNum(DirPartyTable, PrimaryAddressLocation));
dataSource = dataSource.addDataSource(tableNum(OMInternalOrganization), "OMInternalOrganization");
dataSource.addLink(fieldNum(OMInternalOrganization, RecId), fieldNum(DirPartyTable, RecId));
dataSource.joinMode(JoinMode::OuterJoin);
But it doesn't work since I need my projection to start at LogisticsPostalAddress and L..P...A...CountryRegion and DirPartyLocation both need to be linked with LogisticsPostalAddress. At the second time I try to link LogisticsPostalAddress I get an error because the last datasource added was not that one.
I don't know how to do that using QueryBuilder, is it possible? If so, how?
This is the full structure of the query I'm trying to assemble:

Thanks!