#2327 - findSingleAttribute() on a ToMany path includes the id column

This commit is contained in:
rbygrave committed 2021-08-24 14:31:30 +12:00
1 parent b392db866c
commit c4c4663144
3 files changed
+6 -5

No files matched your search

@@ -299,10 +299,10 @@ public final class SqlTreeBuilder {
return new SqlTreeNodeRoot(desc, props, myList, withId, includeJoin, lazyLoadMany, temporalMode, disableLazyLoad, sqlDistinct, baseTable);
} else if (prop instanceof STreePropertyAssocMany) {
return new SqlTreeNodeManyRoot(prefix, (STreePropertyAssocMany) prop, props, myList, temporalMode, disableLazyLoad);
boolean withId = isNotSingleAttribute() && !subQuery;
return new SqlTreeNodeManyRoot(prefix, (STreePropertyAssocMany) prop, props, myList, withId, temporalMode, disableLazyLoad);
} else {
// do not read Id on child beans (e.g. when used with fetch())
boolean withId = isNotSingleAttribute() && !subQuery;
return new SqlTreeNodeBean(prefix, prop, props, myList, withId, temporalMode, disableLazyLoad);
}
@@ -13,8 +13,8 @@ final class SqlTreeNodeManyRoot extends SqlTreeNodeBean {
private final STreePropertyAssocMany manyProp;
SqlTreeNodeManyRoot(String prefix, STreePropertyAssocMany prop, SqlTreeProperties props, List<SqlTreeNode> myList,
SpiQuery.TemporalMode temporalMode, boolean disableLazyLoad) {
super(prefix, prop, props, myList, true, temporalMode, disableLazyLoad);
boolean withId, SpiQuery.TemporalMode temporalMode, boolean disableLazyLoad) {
super(prefix, prop, props, myList, withId, temporalMode, disableLazyLoad);
this.manyProp = prop;
}
@@ -114,12 +114,13 @@ public class TestSubQuery extends BaseTestCase {
List<Integer> productIds = new ArrayList<>();
productIds.add(3);
Query<OrderDetail> sq = DB.createQuery(OrderDetail.class).alias("a").fetch("order.shipments", "id").where()
Query<OrderDetail> sq = DB.createQuery(OrderDetail.class).fetch("order.shipments", "id").where()
.isIn("product.id", productIds).query();
// execute the subQuery as copy (generatedSQL must be part of original query)
Query<OrderDetail> debugSq = sq.copy();
debugSq.findSingleAttribute();
assertThat(debugSq.getGeneratedSql()).contains("select t2.id from o_order_detail a join o_order t1 on t1.id = a.order_id left join or_order_ship t2");
Query<OrderShipment> query = DB.find(OrderShipment.class).select("shipTime").where().isIn("id", sq).query();
query.findSingleAttribute();