gpt4 book ai didi

grails - 关系1 a 1错误插入数据

转载 作者:行者123 更新时间:2023-12-02 15:54:35 26 4
gpt4 key购买 nike

我有一种关系1-1域模型

package relation1a1

class Person {
Home home
String name
String aPaterno
String aMaterno
}

package relation1a1

class Home {

static belongsTo = [person: Person]

String cP
String street
}

当我将数据插入到人员表中时,要求我将数据插入到表的第一项工作中;当我尝试将数据插入到主表中时,要求我将数据插入到人表中。

我尝试做的是消除关系的1-1关系的人。

最佳答案

更改类(class)域:

package relation1a1

class Person {
Home home
String name
String aPaterno
String aMaterno
static constraints = {
home nullable: true //now you can save Person instance with home=null
}
}

然后:
def person = new Person(name: "name", aPaterno: "qwe", aMaterno: "rty")
person.save(flush: true)

def home = new Home(cP: "asd", street: "fgh", person: person)
home.save(flush: true)

person.home = home
person.save()

关于grails - 关系1 a 1错误插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35051430/

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