diff --git a/query/src/org/labkey/query/sql/CalculatedExpressionColumn.java b/query/src/org/labkey/query/sql/CalculatedExpressionColumn.java index eba8446b5c2..34bb8014095 100644 --- a/query/src/org/labkey/query/sql/CalculatedExpressionColumn.java +++ b/query/src/org/labkey/query/sql/CalculatedExpressionColumn.java @@ -121,6 +121,22 @@ public Set getReferencedFieldKeys() return Collections.unmodifiableSet(_allFieldKeys); } + /* getValueSql() inlines the value SQL of every column the expression references, so any join those columns + * declare has to be declared here too -- otherwise the inlined SQL names a table alias that is not in the FROM. + * Lookups and self-reference are rejected during binding, so every referenced key is a plain column on this table. + */ + @Override + public void declareJoins(String parentAlias, Map map) + { + getBoundExpression(); // populates _allFieldKeys + for (FieldKey key : getReferencedFieldKeys()) + { + ColumnInfo col = getParentTable().getColumn(key); + if (null != col && col != this) + col.declareJoins(parentAlias, map); + } + } + public void computeMetaData(Map columns) { if (null == columns)