mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
fix several bugs in findSingleAttibute (#980)
* add test case for distinct on id property * suggested fix for "select distinct id" * add test case for distinct with fetch * FIX: .setDistinct(true) can be used in conjunction with fetch() now * add test case for distinct with beans that have a disriminator column * FIX: discriminator column is only read if also Id is read. * fine tuned the test case * added test cases for findSingleAttributeList without distinct * improved fix to support also findSingleAttribute without distinct * ADD: Bonus test case - assertion not yet verified
This commit is contained in:
committed by
Rob Bygrave
parent
40ca179509
commit
a46e086dc4
@@ -58,7 +58,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
|
||||
* False if report bean and has no id property.
|
||||
*/
|
||||
protected final boolean readId;
|
||||
|
||||
|
||||
private final boolean disableLazyLoad;
|
||||
|
||||
protected final InheritInfo inheritInfo;
|
||||
@@ -89,9 +89,9 @@ class SqlTreeNodeBean implements SqlTreeNode {
|
||||
* Construct for leaf node.
|
||||
*/
|
||||
SqlTreeNodeBean(String prefix, BeanPropertyAssoc<?> beanProp, SqlTreeProperties props,
|
||||
List<SqlTreeNode> myChildren, SpiQuery.TemporalMode temporalMode, boolean disableLazyLoad) {
|
||||
List<SqlTreeNode> myChildren, boolean withId, SpiQuery.TemporalMode temporalMode, boolean disableLazyLoad) {
|
||||
|
||||
this(prefix, beanProp, beanProp.getTargetDescriptor(), props, myChildren, true, null, temporalMode, disableLazyLoad);
|
||||
this(prefix, beanProp, beanProp.getTargetDescriptor(), props, myChildren, withId, null, temporalMode, disableLazyLoad);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,6 +135,11 @@ class SqlTreeNodeBean implements SqlTreeNode {
|
||||
|
||||
@Override
|
||||
public BeanProperty getSingleProperty() {
|
||||
if (properties == null || properties.length == 0) {
|
||||
// if we have no property ask first children (in a distinct select with join)
|
||||
// if we have also no children, NPE happens anyway.
|
||||
return children[0].getSingleProperty();
|
||||
}
|
||||
return properties[0];
|
||||
}
|
||||
|
||||
@@ -162,9 +167,9 @@ class SqlTreeNodeBean implements SqlTreeNode {
|
||||
@Override
|
||||
public void buildRawSqlSelectChain(List<String> selectChain) {
|
||||
if (readId) {
|
||||
if (desc.hasInheritance()) {
|
||||
if (inheritInfo != null) {
|
||||
// discriminator column always proceeds id column
|
||||
selectChain.add(getPath(prefix, desc.getInheritInfo().getDiscriminatorColumn()));
|
||||
selectChain.add(getPath(prefix, inheritInfo.getDiscriminatorColumn()));
|
||||
}
|
||||
idBinder.buildRawSqlSelectChain(prefix, selectChain);
|
||||
}
|
||||
@@ -434,11 +439,11 @@ class SqlTreeNodeBean implements SqlTreeNode {
|
||||
lazyLoadParent.addSelectExported(ctx, prefix);
|
||||
}
|
||||
|
||||
if (!subQuery && inheritInfo != null) {
|
||||
ctx.appendColumn(inheritInfo.getDiscriminatorColumn());
|
||||
}
|
||||
|
||||
if (readId) {
|
||||
if (!subQuery && inheritInfo != null) {
|
||||
ctx.appendColumn(inheritInfo.getDiscriminatorColumn());
|
||||
}
|
||||
|
||||
appendSelectId(ctx, idBinder.getBeanProperty());
|
||||
}
|
||||
appendSelect(ctx, subQuery, properties);
|
||||
|
||||
Reference in New Issue
Block a user