From d4d9bb204df67e5dd9c6ae32887b04e4dab1c1f2 Mon Sep 17 00:00:00 2001 From: rbygrave Date: Tue, 24 Aug 2021 15:04:23 +1200 Subject: [PATCH] #2327 - findSingleAttribute() on a ToMany path includes the id column Follow up refactor SqlTreeBuilder --- .../server/query/SqlTreeBuilder.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java index 5963b84cd..c3e3fb736 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java @@ -299,15 +299,31 @@ public final class SqlTreeBuilder { return new SqlTreeNodeRoot(desc, props, myList, withId, includeJoin, lazyLoadMany, temporalMode, disableLazyLoad, sqlDistinct, baseTable); } else if (prop instanceof STreePropertyAssocMany) { - boolean withId = isNotSingleAttribute() && !subQuery; - return new SqlTreeNodeManyRoot(prefix, (STreePropertyAssocMany) prop, props, myList, withId, temporalMode, disableLazyLoad); + return new SqlTreeNodeManyRoot(prefix, (STreePropertyAssocMany) prop, props, myList, withId(), temporalMode, disableLazyLoad); } else { - boolean withId = isNotSingleAttribute() && !subQuery; - return new SqlTreeNodeBean(prefix, prop, props, myList, withId, temporalMode, disableLazyLoad); + return new SqlTreeNodeBean(prefix, prop, props, myList, withId(), temporalMode, disableLazyLoad); } } + boolean withId() { + return isNotSingleAttribute() && !subQuery; + } + + /** + * Return true if the Id property should be excluded (as it is automatically included). + */ + private boolean excludeIdProperty() { + return query == null || !query.isSingleAttribute() && !query.isManualId(); + } + + /** + * Return true if the query is not a single attribute query. + */ + private boolean isNotSingleAttribute() { + return query == null || !query.isSingleAttribute(); + } + /** * Build extra joins to support properties used in where clause but not * already in select clause. @@ -666,20 +682,6 @@ public final class SqlTreeBuilder { } return extras.toArray(new String[0]); } - } - /** - * Return true if the Id property should be excluded (as it is automatically included). - */ - private boolean excludeIdProperty() { - return query == null || !query.isSingleAttribute() && !query.isManualId(); - } - - /** - * Return true if the query is not a single attribute query. - */ - private boolean isNotSingleAttribute() { - return query == null || !query.isSingleAttribute(); - } }