7
나는 Grails in Action에서 예제를 따르고있다. addTo*()
기능이 어떻게 작동하는지 이해하는 데 문제가 있습니다. Grails addTo * clarification
- 사용자 1에-M 포스트
- 사용자 1에-M 태그
- 후 M-에 -M 태그 나는 다음과 같은 코드를 실행
(첫 번째 경우) :
1. def user = new User(userId: 'joe', password: 'secret').save()
2. def tagGroovy = new Tag(name: 'groovy')
3. def tagGrails = new Tag(name: 'grails')
4. user.addToTags(tagGroovy)
5. user.addToTags(tagGrails)
6.
7. def groovyPost = new Post(content: 'A groovy post')
8. user.addToPosts(groovyPost)
9. groovyPost.addToTags(tagGroovy)
10.
11. User.get(1).tags.each {println it.id + " " + it.name}
12. User.get(1).posts.each {println it.id + " " + it.content + " " + it.dateCreated}
,536,913,632
null grails
null groovy
null A groovy post null
을 그리고 선 4, 5를 변경하는 경우, 그리고 8 : 10
나는이 얻을
2 grails
1 groovy
1 A groovy post Tue Nov 22 21:00:00 WET 2011
누군가가 이유에서 설명 할 수 :
4. user.addToTags(tagGroovy).save(flush: true)
5. user.addToTags(tagGrails).save(flush: true)
8. user.addToPosts(groovyPost).save(flush: true)
나는이 얻을 첫 번째 경우 id
및 dateCreated
속성이 유지되지 않습니까?