Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: The association Post -> User is working, the other way round not:
- groovy:000> u = new User(name:'hoschi', password:'secret').save()
- ===> com.hubbub.User : 1
- groovy:000> t = new Tag(name:'my_tag', user:u).save()
- ===> com.hubbub.Tag : 1
- groovy:000> p = new Post(tags:[t], user:u, content: 'Post content').save()
- ===> com.hubbub.Post : 1
- groovy:000> p.user
- ===> com.hubbub.User : 1
- groovy:000> u.posts
- ===> null
- // User
- class User {
- static hasMany = [ posts : Post, tags : Tag, following : User ]
- String name
- String password
- Profile profile
- //....
- }
- // Post
- class Post {
- static belongsTo = [user:User]
- static hasMany = [tags : Tag]
- }
Add Comment
Please, Sign In to add comment