gpt4 book ai didi

grails - addTo *不保留更改

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

我正在使用grails控制台来处理我的关系。我正在使用Grails in Action书中的练习:

我有关系:

class User {
...

Profile profile

static hasMany = [posts: Post, tags: Tag, following: User]

...


User.get(3).addToFollowing( User.get(2) ).save()
User.list().each { print it.following }

产量

null null [com.grailsinaction.User : 2] null null



并再次运行:
User.get(1).addToFollowing( User.get(2) ).save()    
User.list().each { print it.following }



[com.grailsinaction.User : 2] null null null null



好像第一个 addToFollowing丢失了...我忘记了什么吗?

最佳答案

尝试使用:

User.get(3).addToFollowing( User.get(2) ).save(flush: true)

除非使用flush参数,否则不会立即保留该对象。 请参阅相关的 link

关于grails - addTo *不保留更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19908762/

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