【发布时间】:2013-07-06 04:08:22
【问题描述】:
我有一个域类 UserProfile,它与另一个域类 User 具有一对一的关系。提供了域的结构。
сlass UserProfile {
String fio
String position
String phone
String email
static belongsTo = [user: User]
static constraints = {
// some constraints
}
static mapping = {
//some mapping; user property is not mapped
}
我需要在 Grails 中为 UserProfile 域编写本机 sql 查询,但我不知道如何引用用户属性(静态 belongsTo = [user: User])。我试过 USER_ID 但它不起作用。 我不能直接使用映射部分命名列;我只需要找出 UserProfile 域中的用户列在数据库中是如何命名的,以及如何在本机 sql 查询中调用它。
【问题讨论】:
-
如果您只需要查看架构详细信息,则运行
grails schema-export,它将生成架构到target/ddl.sql。 grails.org/doc/2.2.1/ref/Command%20Line/schema-export.html