0
我需要运行2个遗留表的查询,但无论是连接列不是主键,通过实例更加清晰:的Grails GORM如何加入原有表上指定的键
的2一到一个域类:
class DocumentStatus {
String id
String messageID
static hasOne = [activity: Activity]
static constraints = {
activity unique: true
}
static mapping = {
datasource 'messages'
table 'DocumentStatus'
cache usage: 'read-only'
version false
id column: 'UniqueID', generator: 'assigned'
messageID column: 'MessageID', insertable: false, updateable: false
activity column: 'MessageID', ignoreNotFound: true, cache: true, /*lazy: false, */fetch: 'join'
}
}
和
class Activity {
String id
String messageId
DocumentStatus documentStatus
static belongsTo = [DocumentStatus]
static mapping = {
datasource 'messages'
version false
cache usage: 'read-only'
table 'Activity'
id column: 'aid', generator: 'assigned'
messageId column: 'messageid', insertable: false, updateable: false
documentStatus column: 'messageid', cache: true
}
static constraints = {
documentStatus unique: true
}
}
的SQL运行是(这里只显示重要组成部分):
"inner join activity activity_a1_ on this_.uniqueid=activity_a1_.messageid "
但我需要的是将DocumentStatus又名“this_”上的连接列更改为“messageId”。
where子句主要是:
def query = DocumentStatus.where {
dateTime >= dateFrom && dateTime <= dateTo &&
status in docStatusList
}
if (buyerId) {
query = query.where {
activity.senderId == buyerId
}
}
def results = query.list(sort: "dateTime", max: 100)
我已经试过各种组合,但不能得到比较是messageId
上的连接两侧。