tags:

views:

39

answers:

1

I have two Domain classes (Drives & Computer)

class Computer {

    static hasMany = [drives:Drive]
    String computerName

    static constraints = {
    computerName(nullable:false)
    }
}


class Drive {

    static belongsTo = Computer
    Computer computerName

    static constraints = {
    computerName(nullable:false)
    }
}

When the application is run and the DriveController is clicked, the drop menu for Computer Name shows something like: computer: 1

My desired output is what I actually have entered for the computer: 1 which in my instance was Owner987

I have generated my views and believe I need to edit a g.link, perhaps in show.gsp of Drive.

All help is appreciated.

+4  A: 

By default it will show the toString() output, so override that to show what you want:

class Computer {

    static hasMany = [drives:Drive]
    String computerName

    String toString() { computerName }
}

Also note that properties are not-null by default so you can omit the nullable:false constraints in both classes.

Burt Beckwith
Thank you Burt for showing me and explaining that. It's definitely nice having someone that'll teach newcomers :]Also, sorry that it won't let me up-vote your response (as I'm not registered) perhaps someone will come by and up-vote your response for me
Philip
Just thought I would add one another question, is there a way to keep computerName from showing duplicate entries in Drive?
Philip