2
votes

I have a domain class with a Collection of simple Strings as one of it's members

class Customer {
    String name;

    static hasMany = [ aliases:String ]

    static constraints = {
        name blank:false
    }
}

I'm wondering if I can add the aliases to the grails scaffolding? and if so, how?

Thanks,

1

1 Answers

2
votes

Grails does not do scaffolding for arrays. The hasMany is designed to be used with another domain class, not a variable. Using hasMany with a domain class will generate automatic scaffolding. For example

class Customer {
    String name;
    static hasMany = [ aliases:Alias ]
    static constraints = {
        name blank:false
    }
}
class Alias {
    String alias;
    static constraints = {
        alias blank:false
    }
}

This would create two tables, customer and alias. A foreign key would be used to associate records in the alias table with a customer. The collection of aliases would be accessed by

alias[0].alias

If you have to use an array instead of another domain class you will have to write custom code for the user interface.