Inheritance domain classes in Grails

Posted by Tomáš on Stack Overflow See other posts from Stack Overflow or by Tomáš
Published on 2010-05-28T09:35:39Z Indexed on 2010/05/28 9:41 UTC
Read the original article Hit count: 284

Filed under:

Hi gurus

how can I get Collection of specific Class?

I use inheriance: On Planet live Human. Humans are dividing to Men and Women.

class Planet{
   String name
   static hasMany = [ humans : Human ]
}

class Human{
    String name
    static belongsTo = [Planet]
}

class Man extends Human{
     int countOfCar
}

class Woman extends Human{
     int coutOfChildren  
}

now a neet to get only Collection of Man or Collection of Woman:

get all humans on planet is simple

all = Planet.get(1).humans

but what can I get only woman or men?
womenLivedOnMars = Planet.get(1).getOnlyWoman
menLivedOnJupiter = Planet.get(2).getOnlyMan

Thanks for your help
Tom

© Stack Overflow or respective owner

Related posts about grails