diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/ExportAction.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/ExportAction.java index 406c1a41..6bd4b83d 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/ExportAction.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/reporting/ExportAction.java @@ -197,7 +197,27 @@ public class ExportAction String joinTableName = parts[0]; if(!addedJoinNames.contains(joinTableName)) { - queryJoins.add(new QueryJoin(joinTableName).withType(QueryJoin.Type.LEFT).withSelect(true)); + QueryJoin queryJoin = new QueryJoin(joinTableName).withType(QueryJoin.Type.LEFT).withSelect(true); + queryJoins.add(queryJoin); + + ///////////////////////////////////////////////////////////////////////////////////////////// + // in at least some cases, we need to let the queryJoin know what join-meta-data to use... // + // This code basically mirrors what QFMD is doing right now, so it's better - // + // but shouldn't all of this just be in JoinsContext? it does some of this... // + ///////////////////////////////////////////////////////////////////////////////////////////// + QTableMetaData table = exportInput.getTable(); + Optional exposedJoinOptional = CollectionUtils.nonNullList(table.getExposedJoins()).stream().filter(ej -> ej.getJoinTable().equals(joinTableName)).findFirst(); + if(exposedJoinOptional.isEmpty()) + { + throw (new QException("Could not find exposed join between base table " + table.getName() + " and requested join table " + joinTableName)); + } + ExposedJoin exposedJoin = exposedJoinOptional.get(); + + if(exposedJoin.getJoinPath().size() == 1) + { + queryJoin.setJoinMetaData(QContext.getQInstance().getJoin(exposedJoin.getJoinPath().get(exposedJoin.getJoinPath().size() - 1))); + } + addedJoinNames.add(joinTableName); } }