Announcement Announcement Module
Collapse
No announcement yet.
Multiple unidirectional one-to-many not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple unidirectional one-to-many not working

    Hi,
    I'm new to Grails. I'm having the folling problem with my database model:
    Two of my domain classes (User and Post) have multiple one-to-many associations between them. User may like, dislike, see or own multiple Posts. For this I have set up hasMany relationship as following:

    Code:
    static hasMany = [posts:Post, seen:Post, likes:Post, dislikes:Post]
    After developing owning side of my code when I started to work with seen I saw that each object that is in posts list is also in seen, likes and dislikes. Then I tried to use joinTable to map tables:

    Code:
    static mapping = {
        posts joinTable: [name: 'USER_POSTS',
            column: 'POST_ID',
            key: 'USER_ID']
        seen joinTable: [name: 'USER_SEEN',
            column: 'POST_ID',
            key: 'USER_ID']
        likes joinTable: [name: 'USER_LIKES',
            column: 'POST_ID',
            key: 'USER_ID']
        dislikes joinTable: [name: 'USER_DISLIKES',
            column: 'POST_ID',
            key: 'USER_ID']
    }
    But unfortunately nothing changed, posts added to posts still go to other lists too.
    What would you suggest to do?
Working...
X