John
John

Reputation: 259

Grails Domain Classes Dates

I have this domain class:

class activity {

    String name
    Date startDate
    Date endDate


    static constraints = {

    }
}

What i want to do is:

a) apply constrains to the dates, for example minimum date and maximum date

b) in my project i need to have an Array of dates and add as many endDates as i want. is it possible to do so? and how

Upvotes: 0

Views: 1925

Answers (2)

Dónal
Dónal

Reputation: 187499

a) apply constrains to the dates, for example minimum date and maximum date

Here's an example of a minimum and maximum constraint applied to the startDate field

class activity {

    String name
    Date startDate
    Date endDate

    static constraints = {

        // date must be between today and today + 7 days
        startDate(min: new Date(), max: newDate() + 7)
    }
}

Upvotes: 2

Gregg
Gregg

Reputation: 35864

A good reading of the Grails docs would answer a lot of the questions you've been asking here.

a) Adding Custom Validation to a Field

b) If I understand you correctly, what you might want to do is create another class called something like ActivityEndDate and then build your domain like this:

class Activity {

   // regular properties

   static hasMany = [endDates:ActivityEndDate]   

}

Again, the docs are helpful here.

Upvotes: 0

Related Questions