Sri
Sri

Reputation: 1505

How to Restrict hasMany with limited numbers in domain class in grails

I am developing a grails application, I have domain classes like Tip, TipTag. Concept is, For a Tip I should have only 5 TipTag.

class Tip {
    String description
    static hasMany = [tags:TipTag]

    static constraints = {
        description(nullable:false,size:50..500)
    }   
}

How to restrict this in grails?? Any other way of doing this???

Upvotes: 1

Views: 898

Answers (1)

aiolos
aiolos

Reputation: 4697

The maxSize constraint should do the job for you:

class Tip {
    String description
    static hasMany = [tags:TipTag]

    static constraints = {
        description(nullable:false,size:50..500)
        tags(maxSize: 5)
    }   
}

Upvotes: 3

Related Questions