mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
Fix for #158 - Add support for using setDistinct (by excluding id property from generated sql)
This commit is contained in:
1 parent
af9a01be77
commit
5cc2eff0d4
8 files changed
+133
-24
No files matched your search
@@ -144,7 +144,7 @@ public class CQueryBuilder implements Constants {
|
||||
String sqlSelect = "select count(*)";
|
||||
if (hasMany) {
|
||||
// need to count distinct id's ...
|
||||
query.setDistinct(true);
|
||||
query.setSqlDistinct(true);
|
||||
sqlSelect = null;
|
||||
}
|
||||
|
||||
@@ -320,13 +320,13 @@ public class CQueryBuilder implements Constants {
|
||||
|
||||
if (!useSqlLimiter) {
|
||||
sb.append("select ");
|
||||
if (query.isDistinct()) {
|
||||
if (query.isDistinctQuery()) {
|
||||
sb.append("distinct ");
|
||||
}
|
||||
}
|
||||
|
||||
sb.append(select.getSelectSql());
|
||||
if (query.isDistinct() && dbOrderBy != null) {
|
||||
if (query.isDistinctQuery() && dbOrderBy != null) {
|
||||
// add the orderby columns to the select clause (due to distinct)
|
||||
sb.append(", ").append(convertDbOrderByForSelect(dbOrderBy));
|
||||
}
|
||||
|
||||
@@ -258,7 +258,8 @@ public class SqlTreeBuilder {
|
||||
|
||||
// Optional many property for lazy loading query
|
||||
BeanPropertyAssocMany<?> lazyLoadMany = (query == null) ? null : query.getLazyLoadForParentsProperty();
|
||||
return new SqlTreeNodeRoot(desc, props, myList, !subQuery, includeJoin, lazyLoadMany);
|
||||
boolean withId = !subQuery && (query == null || !query.isDistinct());
|
||||
return new SqlTreeNodeRoot(desc, props, myList, withId, includeJoin, lazyLoadMany);
|
||||
|
||||
} else if (prop instanceof BeanPropertyAssocMany<?>) {
|
||||
return new SqlTreeNodeManyRoot(prefix, (BeanPropertyAssocMany<?>) prop, props, myList);
|
||||
@@ -312,7 +313,7 @@ public class SqlTreeBuilder {
|
||||
// as we are now going to join to the many then we need
|
||||
// to add the distinct to the sql query to stop duplicate
|
||||
// rows...
|
||||
query.setDistinct(true);
|
||||
query.setSqlDistinct(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ public class SqlTreeNodeBean implements SqlTreeNode {
|
||||
|
||||
Mode queryMode = ctx.getQueryMode();
|
||||
|
||||
PersistenceContext persistenceContext = ctx.getPersistenceContext();
|
||||
PersistenceContext persistenceContext = !readId ? null : ctx.getPersistenceContext();
|
||||
|
||||
Object id = null;
|
||||
if (!readId) {
|
||||
@@ -274,8 +274,9 @@ public class SqlTreeNodeBean implements SqlTreeNode {
|
||||
} else if (localBean != null) {
|
||||
|
||||
ctx.setCurrentPrefix(prefix, pathMap);
|
||||
createListProxies(localDesc, ctx, localBean);
|
||||
|
||||
if (readId) {
|
||||
createListProxies(localDesc, ctx, localBean);
|
||||
}
|
||||
localDesc.postLoad(localBean, null);
|
||||
|
||||
if (localBean instanceof EntityBean) {
|
||||
@@ -290,7 +291,10 @@ public class SqlTreeNodeBean implements SqlTreeNode {
|
||||
}
|
||||
|
||||
if (partialObject) {
|
||||
ctx.register(null, ebi);
|
||||
if (readId) {
|
||||
// register for lazy loading
|
||||
ctx.register(null, ebi);
|
||||
}
|
||||
} else {
|
||||
ebi.setFullyLoadedBean(true);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user