0

We use dynamic scaffolding in our project and hence place maximum coding in Domain itself.

I have a requirement where I want to retrieve a collection for a Domain class property from the same domain class. Example :

class Person{

String name

String school

}

school property should be a dropdown containing list of all schools so far available in the Person table. If no value available, it can be empty dropdown.

Any suggestions to achieve this in domain class itself?

Alexander Vogt
  • 17,879
  • 13
  • 52
  • 68

1 Answers1

0

That is what static hasMany is for: http://grails.org/doc/latest/ref/Domain%20Classes/hasMany.html

in your case, something like below will work , once you create a School Domain object:

class Person{

...

static hasMany = [schools: School]
...
Vinny
  • 789
  • 8
  • 16
  • Thanks. I understand it can be achieved via another domain object. I do not have a separate table for 'School'. I cannot create one new table too as the database is existing one and cannot be modified. School is just one of the rows of Person table. So, just to avoid complex mappings, we just look for kind of shortcut in same Domain class. – user1304693 Oct 15 '13 at 13:37