Guest User

Untitled

a guest
Aug 10th, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. // Problem: The association Post -> User is working, the other way round not:
  2.  
  3. groovy:000> u = new User(name:'hoschi', password:'secret').save()
  4. ===> com.hubbub.User : 1
  5. groovy:000> t = new Tag(name:'my_tag', user:u).save()
  6. ===> com.hubbub.Tag : 1
  7. groovy:000> p = new Post(tags:[t], user:u, content: 'Post content').save()
  8. ===> com.hubbub.Post : 1
  9. groovy:000> p.user
  10. ===> com.hubbub.User : 1
  11. groovy:000> u.posts
  12. ===> null
  13.  
  14. // User
  15.  
  16. class User {
  17. static hasMany = [ posts : Post, tags : Tag, following : User ]
  18.  
  19. String name
  20. String password
  21. Profile profile
  22. //....
  23. }
  24.  
  25. // Post
  26.  
  27. class Post {
  28. static belongsTo = [user:User]
  29. static hasMany = [tags : Tag]
  30. }
Add Comment
Please, Sign In to add comment