문제

I'm using the grails console to play with my relationships. I'm using the excersises on the book Grails in Action:

I have the relationship:

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   } 

yields

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

and again running:

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

gives

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

Looks like the first addToFollowing is lost... did I forget anything?

도움이 되었습니까?

해결책

Try to use:

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

The object will not be persisted immediately unless the flush argument is used. See related link.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top