Quantcast

Why grails doesn't deep validate non owning "one" side of many-to-one association?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Why grails doesn't deep validate non owning "one" side of many-to-one association?

dmurat
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Why grails doesn't deep validate non owning "one" side of many-to-one association?

dmurat
If full explanation is too much :-), just will like to know for sure, is this desired behavior or maybe a bug? Tnx.
Loading...