Skip to content

Commit

Permalink
Merge branch 'master' of github.com:grails/grails-core
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Apr 22, 2010
2 parents 0e00064 + a514a74 commit f51ba80
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,14 @@ else if (!"ordinal".equalsIgnoreCase(enumType)) {
simpleValue.setTypeParameters(enumProperties);
Table t = simpleValue.getTable();
Column column = new Column();
column.setNullable(property.isOptional());

if (property.getDomainClass().isRoot()) {
column.setNullable(property.isOptional());
} else {
if (LOG.isDebugEnabled())
LOG.debug("[GrailsDomainBinder] Sub class property [" + property.getName() + "] for column name ["+column.getName()+"] set to nullable");
column.setNullable(true);
}
column.setValue(simpleValue);
column.setName(columnName);
if (t != null) t.addColumn(column);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,43 @@ class Vehicle2 {
status enumType:'ordinal'
}
}
class SuperClass {Long id; Long version;}
class SubClassWithStringProperty extends SuperClass {
Long id
Long version
String someProperty
}
class SubClassWithEnumProperty extends SuperClass {
VehicleStatus vehicalStatus
}
class SubClassWithOptionalEnumProperty extends SuperClass {
VehicleStatus optionalVehicalStatus
static constraints = {
optionalVehicalStatus nullable: true
}
}
''')
}

void testEnumNullabilityWithTablePerHierarchy() {
def vehicleEnum = ga.classLoader.loadClass("VehicleStatus")
def domainClassWithStringProperty = ga.getDomainClass('SubClassWithStringProperty').clazz
def domainClassWithEnumProperty = ga.getDomainClass('SubClassWithEnumProperty').clazz
def domainClassWithOptionalEnumProperty = ga.getDomainClass('SubClassWithOptionalEnumProperty').clazz

def domainObject = domainClassWithStringProperty.newInstance()
domainObject.someProperty = 'data'
assertNotNull domainObject.save()

domainObject = domainClassWithEnumProperty.newInstance()
assertNull domainObject.save()
domainObject.vehicalStatus = vehicleEnum.IDLING
assertNotNull domainObject.save()

domainObject = domainClassWithOptionalEnumProperty.newInstance()
assertNotNull domainObject.save()
}

void testDefaultEnumMapping() {
def vehicleClass = ga.getDomainClass("Vehicle").clazz
def vehicleEnum = ga.classLoader.loadClass("VehicleStatus")
Expand Down

0 comments on commit f51ba80

Please sign in to comment.