mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1408 - Incorrect SQL when @Aggregation formula matches the property - sum(t0.sum(totalKms))
This commit is contained in:
@@ -647,11 +647,35 @@ public class DeployBeanProperty {
|
||||
*/
|
||||
public String parseAggregation() {
|
||||
if (aggregation != null) {
|
||||
int pos = aggregation.indexOf('(');
|
||||
if (pos > -1) {
|
||||
// check for recursive property name and formula
|
||||
String maybePropertyName = aggregation.substring(pos + 1, aggregation.length() - 1);
|
||||
if (name.equals(maybePropertyName)) {
|
||||
// e.g. bean property cost mapped to sum(cost)
|
||||
return aggregationJoin(pos, dbColumn);
|
||||
} else {
|
||||
DeployBeanProperty other = desc.getBeanProperty(maybePropertyName);
|
||||
if (other != null) {
|
||||
// e.g. bean property maxKms mapped to sum(totalKms) where totalKms is another property
|
||||
return aggregationJoin(pos, other.getDbColumnRaw());
|
||||
}
|
||||
}
|
||||
}
|
||||
aggregationParsed = desc.parse(aggregation);
|
||||
}
|
||||
return aggregationParsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple aggregation parsing like sum(someProperty)
|
||||
*/
|
||||
private String aggregationJoin(int pos, String dbColumn) {
|
||||
String p0 = aggregation.substring(0, pos + 1);
|
||||
aggregationParsed = p0 + "${ta}." + dbColumn + aggregation.substring(aggregation.length() - 1);
|
||||
return aggregationParsed;
|
||||
}
|
||||
|
||||
public void setAggregation(String aggregation) {
|
||||
this.aggregation = aggregation;
|
||||
this.dbRead = true;
|
||||
@@ -702,6 +726,13 @@ public class DeployBeanProperty {
|
||||
return dbColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DB column without any aggregation parsing.
|
||||
*/
|
||||
private String getDbColumnRaw() {
|
||||
return dbColumn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the database column name this is mapped to.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user