mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 05:35:54 +00:00
#945 - Invalid SQL when using @Aggregation with a fetch() to a ManyToOne - missing columns in GROUP BY
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user