开发者

Grails newbie - Scaffold question - Replace unique id with readable value(s)?

I'm creating a web application with grails, and I'm working on the CRUD prototype using Scaffold. Out of the box, the scaffold will use the unique id (which makes sense) for foreign key values, and I'm wondering if I can easily replace the unique id with a readable value (such as a combination of two values from said table).

For example: I have Location and RoomNumber domains that represent a Hotel location and room number. Each number therefore "belongs-to" a location. When I go to create a room, I have a开发者_StackOverflow中文版 drop-down auto-generated that allows me to pick from existing locations. These are unintuitive values though... such as "project.Location : 1"

I'd like to replace this "project.Location : 1" with the name, city, and state column values that correspond to id 1. Is this an easy thing to modify? I'd think there's some simple mapping that needs to be done...

Thanks in advance!


Turns out the solution is really simple... just need to implement the toString method in the corresponding Domain class. Received this answer from the Grails mailing list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜