|
|
Say I have these two domain classes:
class House {
String name
Address address
static constraints = {
name(blank:false)
address(nullable:true)
}
}
class Address {
String street
// static belongsTo = House
static constraints = {
street(blank:false)
}
}
and integration test
class HouseIntegrationTests extends GroovyTestCase {
void testAddressConstraints() {
House house = new House(name:'some name', address: new Address(street: ''))
assert !house.validate()
assert 'blank' == house.errors['address.street'].code
}
}
With above code, test will fail, but if belongsTo line is uncommented, it will succeed.
org.codehaus.groovy.grails.validation.GrailsDomainClassValidator.cascadeValidationToOne(...) contains a check
if (associatedDomainClass == null || !isOwningInstance(bean, associatedDomainClass)) {
return;
}
which clearly expresses intention not to validate non owning "one" side of relation. This is not really clear to me.
It seems to me that validation should not depend on under laying database schema like that. Is this a bug, or desired behavior?
Can somebody explain, please? Tnx.
|