#945 - Invalid SQL when using @Aggregation with a fetch() to a ManyToOne - missing columns in GROUP BY

This commit is contained in:
Rob Bygrave
2017-01-12 00:42:27 +13:00
parent d9147327c1
commit 2fa4345742
2 changed files with 15 additions and 0 deletions
@@ -397,6 +397,9 @@ class SqlTreeNodeBean implements SqlTreeNode {
property.appendSelect(ctx, subQuery);
}
}
for (SqlTreeNode aChildren : children) {
aChildren.appendGroupBy(ctx, subQuery);
}
ctx.popTableAlias();
ctx.popJoin();
}
@@ -127,4 +127,16 @@ public class TestAggregationCount extends BaseTestCase {
assertThat(query1.getGeneratedSql()).contains("having count(u1.id) >= ? order by t0.name");
}
@Test
public void testSelectWithFetch() {
Query<TEventOne> query0 = Ebean.find(TEventOne.class)
.select("name, count")
.fetch("event", "name");
query0.findList();
String sql = sqlOf(query0, 5);
assertThat(sql).contains("select t0.id, t0.name, count(u1.id), t1.id, t1.name from tevent_one t0 left join tevent t1 on t1.id = t0.event_id join tevent_many u1 on u1.event_id = t0.id ");
assertThat(sql).contains("group by t0.id, t0.name, t1.id, t1.name");
}
}