Skip to content

Commit 50b87f0

Browse files
GRAILS-8482 - Fix derived properties defined in subclass
1 parent b2d68e6 commit 50b87f0

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

grails-hibernate/src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/cfg/GrailsDomainBinder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,9 @@ private static void bindSubClass(GrailsDomainClass sub, PersistentClass parent,
14081408
// to perform polymorphic queries
14091409
Mapping subMapping = getMapping(sub);
14101410
subClass.setDiscriminatorValue(subMapping != null && subMapping.getDiscriminator() != null ? subMapping.getDiscriminator() : sub.getFullName());
1411+
if(subMapping != null) {
1412+
configureDerivedProperties(sub, subMapping);
1413+
}
14111414
}
14121415

14131416
subClass.setEntityName(sub.getFullName());

grails-test-suite-persistence/src/test/groovy/org/codehaus/groovy/grails/orm/hibernate/DerivedPropertiesTests.groovy

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ class ClassWithConstrainedDerivedProperty {
2626
numberTwo max: 10
2727
}
2828
}
29+
30+
@Entity
31+
class AbstractBaseClass {
32+
String one
33+
String two
34+
}
35+
36+
@Entity
37+
class SubClass extends AbstractBaseClass {
38+
String three
39+
static mapping = {
40+
three formula: 'CONCAT(one, two)'
41+
}
42+
}
2943
'''
3044
}
3145

@@ -35,6 +49,12 @@ class ClassWithConstrainedDerivedProperty {
3549
protected void onTearDown() {
3650
}
3751

52+
void testDerivedPropertyDefinedInSubclassIsNotConstrained() {
53+
def mdc = ga.getDomainClass('SubClass')
54+
def mc = mdc.clazz
55+
assertFalse 'three should not have been constrained', mdc.constrainedProperties.containsKey('three')
56+
}
57+
3858
void testDerivedPropertiesCannotBeMadeValidateable() {
3959

4060
def myDomainClass = ga.getDomainClass('ClassWithConstrainedDerivedProperty')

0 commit comments

Comments
 (0)