Grails - ORM加入显示名称与ID [英] Grails - ORM join to show name vs id
本文介绍了Grails - ORM加入显示名称与ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表格
ResourceType:
{
名称
}
示例:Developer,Manager,Director
我有一张
资源:
{
名称,
ResourceType资源类型
}
例如:Develper类型的Bob Jones。格雷斯史密斯的类型经理
我定义工作得到的关系显示在网络上的数据接口:
ResourceType:
名称,Resource_Id
问题是,我收到了:
Bob Jones,0
Grace Smith,1
Alex Rodgers,1
我想让视图显示ResourceType的名称:
Bob Jones ,开发人员
Grace Smith,经理
Alex Rodgers,经理
另外,对于新的数据条目,下拉列表应该列出来自ResourceType而不是Ids的名称。
重写toString()方法 ResourceType
可能有帮助。 字符串toString(){
名称
}
Using scaffolding to develop a simple CRUD for accessing Resource.
I have a table with
ResourceType:
{
Name
}
Example: Developer, Manager, Director
I have a table of
Resource:
{
Name,
ResourceType resourcetype
}
Example: Bob Jones of type Develper. Grace Smith of type Manager
I have the definition working to get the relationship to show the data on the web interface: ResourceType: Name, Resource_Id
The problem is that I am getting:
Bob Jones, 0
Grace Smith, 1
Alex Rodgers, 1
I want to have the view show the name from the ResourceType:
Bob Jones, Developer
Grace Smith, Manager
Alex Rodgers, Manager
Also, for new data entry, the drop down should list the names from ResourceType rather than the Ids.
解决方案
Overriding toString() method of ResourceType
might help.
String toString() {
Name
}
这篇关于Grails - ORM加入显示名称与ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文