grails-data-mapping icon indicating copy to clipboard operation
grails-data-mapping copied to clipboard

minSize validation does not validate correctly on collections

Open tmanthey opened this issue 6 years ago • 3 comments

Steps to Reproduce

  1. define following domain class

class mytest { def my_data = "123" static hasMany = [childItems: mytest] static constraints = { childItems minSize: 1 } } 2. execute the following code

def mytest = new mytest() mytest.save(failOnError: true, flush: true) def result = mytest.validate()

Expected Behaviour

According http://docs.grails.org/3.1.1/ref/Constraints/minSize.html

minSize: Sets the minimum size of a collection or number property

Hence result should be false

Actual Behaviour

result is true

Environment Information

  • Operating System: Ubuntu 16.04
  • GORM Version: gormVersion=6.1.10.RELEASE
  • Grails Version (if using Grails): 3.3.8
  • JDK Version: 1.8.0_201

tmanthey avatar Feb 18 '19 08:02 tmanthey

If minSize is set to 2 and you add just 1 item, does validation fail?

jeffscottbrown avatar Feb 18 '19 15:02 jeffscottbrown

If minSize is set to 2 and you add just 1 item, does validation fail?

Yes it fails as expected. Guess you know why you are asking ;-)

tmanthey avatar Feb 18 '19 16:02 tmanthey

Guess you know why you are asking

Correct.

jeffscottbrown avatar Feb 18 '19 17:02 jeffscottbrown