Add STI Discrimination on Reference Associations (#2041)

* Update SqlTreeNodeBean#appendFromBaseTable to add
discriminator values to the join
* Update tests to reflect new generated SQL
This commit is contained in:
peterko2017
2020-08-05 16:33:34 +12:00
committed by GitHub
parent 4eda4201de
commit 4ef5abceca
5 changed files with 52 additions and 10 deletions
@@ -667,6 +667,9 @@ class SqlTreeNodeBean implements SqlTreeNode {
*/
SqlJoinType appendFromBaseTable(DbSqlContext ctx, SqlJoinType joinType) {
SqlJoinType sqlJoinType = appendFromAsJoin(ctx, joinType);
if (inheritInfo != null) {
appendJoinDiscriminator(ctx);
}
if (desc.isSoftDelete() && temporalMode != SpiQuery.TemporalMode.SOFT_DELETED) {
ctx.append("and ").append(desc.getSoftDeletePredicate(ctx.getTableAlias(prefix))).append(" ");
}
@@ -695,6 +698,12 @@ class SqlTreeNodeBean implements SqlTreeNode {
return nodeBeanProp.addJoin(joinType, prefix, ctx);
}
void appendJoinDiscriminator(DbSqlContext ctx) {
if (inheritInfo.getWhere() == null) return;
String alias = ctx.getTableAlias(prefix);
ctx.append(" and ").append(alias).append(".").append(inheritInfo.getWhere());
}
/**
* Summary description.
*/