#2195 - @Aggregation on OneToMany property not mapping to column properly

This commit is contained in:
Robin Bygrave
2021-03-15 22:03:14 +13:00
parent e6faf9efd1
commit 733886c70b
6 changed files with 34 additions and 21 deletions
@@ -324,9 +324,9 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
this.generatedProperty = deploy.getGeneratedProperty();
this.getter = deploy.getGetter();
this.setter = deploy.getSetter();
this.aggregation = deploy.parseAggregation();
this.dbColumn = tableAliasIntern(descriptor, deploy.getDbColumn(), false, null);
this.dbComment = deploy.getDbComment();
this.aggregation = deploy.parseAggregation();
this.sqlFormulaJoin = InternString.intern(deploy.getSqlFormulaJoin());
this.sqlFormulaSelect = InternString.intern(deploy.getSqlFormulaSelect());
this.formula = sqlFormulaSelect != null;
@@ -16,6 +16,7 @@ import io.ebean.event.BeanPostLoad;
import io.ebean.event.BeanQueryAdapter;
import io.ebean.event.changelog.ChangeLogFilter;
import io.ebean.text.PathProperties;
import io.ebean.util.SplitName;
import io.ebeaninternal.api.ConcurrencyMode;
import io.ebeaninternal.server.core.CacheOptions;
import io.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
@@ -1149,8 +1150,21 @@ public class DeployBeanDescriptor<T> {
return null;
}
// use 'current' table alias - refer BeanProperty appendSelect() for aggregation
DeployBeanProperty property = propMap.get(expression);
return (property == null) ? null : "${ta}." + property.getDbColumn();
String[] split = SplitName.split(expression);
if (split[0] == null) {
DeployBeanProperty property = propMap.get(expression);
return (property == null) ? null : "${ta}." + property.getDbColumn();
} else {
DeployBeanProperty property = propMap.get(split[0]);
if (property instanceof DeployBeanPropertyAssoc) {
DeployBeanPropertyAssoc<?> prop = (DeployBeanPropertyAssoc<?>) property;
DeployBeanProperty beanProperty = prop.getTargetDeploy().getBeanProperty(split[1]);
if (beanProperty != null) {
return "u1." + beanProperty.getDbColumn();
}
}
return null;
}
}
/**
@@ -682,7 +682,6 @@ public class DeployBeanProperty {
*/
public void setAggregationPrefix(String prefix) {
this.aggregationPrefix = prefix;
this.aggregation = (prefix == null) ? aggregation : aggregation.replace(aggregationPrefix, "u1");
}
public String getElPrefix() {
@@ -715,7 +714,7 @@ public class DeployBeanProperty {
return sqlFormulaSelect;
}
if (aggregation != null) {
return aggregation;
return aggregationParsed == null ? dbColumn : aggregationParsed;
}
return dbColumn;
}