I'm learning grails, and I have a problem.
I have 2 classes, lets say:
class Book {
String name
String description
static belongsTo = Category
Category category
static constraints = {
name(nullable:false, blank:false)
description(nullable:true, maxSize:5000)
}
class Category {
String name
static hasMany = [books:Book]
Set books
static constraints = {
name(nullable:false, blank:false)
}
String toString(){
this.name
}
}
When I create a book I want to see a drop down list with all the categories name. If I don't select a category than I shouldn't be able to create that book. If there are no categories in the database than I shouldn't be able to create a book, until I create and select a category.
Is possible for this features to be generated (with grails generate-all) from the domain classes if I have the right constraints and fields? If yes, how?