【发布时间】:2013-06-23 22:03:57
【问题描述】:
我是 Groovy 和 HQL 查询的新手,但我在任何地方都找不到解决方案,所以这让我抓狂。
我有两个定义了一对多关系的域类(一个用户可以有许多公司),我实际上需要做(传统上称为)“表连接”,但显然是对象。
课程是这样的:
class User {
transient springSecurityService
static hasMany = [company: Company]
String username
String password
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
...
...
...
}
...和公司类
class Company {
static scaffolding = true
String name
String address1
String address2
String address3
String address4
String postCode
String telephone
String mobile // mobile number to receive appointment text messages to
String email // email address to receive appointment emails to
static hasMany = [staff: Staff]
static belongsTo = [user: User]
...
...
...
}
Gorm 已在 company 表中创建了一个 user_id 字段,但任何尝试在查询中使用它都会返回错误。
那么我该怎么做:
select * from user u, company c, where u.id = c.user_id;
最好的方法是什么?
【问题讨论】:
标签: grails join hql grails-orm