gpt4 book ai didi

grails - Grails中具有关联的多个数据源

转载 作者:行者123 更新时间:2023-12-02 14:50:47 24 4
gpt4 key购买 nike

在我目前的项目中,我需要使用2个数据库,一个用于主数据,另一个用于客户数据。到目前为止,我们正在使用单个数据库,但我们计划将其拆分为2个数据库(主数据库和客户数据库)。

在域类级别上,客户端和主数据库之间具有关联。我尝试了grails 2.X多个数据源选项,但无法关联。如果有人在这种情况下工作,建议我最好的方法。

我们倾向于对所有客户端实例使用单个主数据库。

最佳答案

我基于此answer解决方案:

class ClassB {
Long classAId

static constraints = {
classAId nullable: true
}

static mapping = {
datasource 'other'
}

static transients = ['classA']

ClassA getClassA(){
classAId ? ClassA.get(classAId) : null
}

ClassB(classAId){
def test = ClassA.get(classAId)
classAId = test ? test.id : null
}
}

也许它不是很漂亮,但是可以正常工作。

关于grails - Grails中具有关联的多个数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30908458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com