title: GORM ASSOCIATION EXPLANATION
body: <p>I need help creating association among Domain Classes. I have three domains: User, News, Comments. A User can make many comments on many news. A news can have many comments from many users.</p>
  
  <p>I am having a big problem implementing this association in GORM.</p>
  
  <p><a href="https://i.stack.imgur.com/JB2k7.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JB2k7.jpg" alt="Gorm Assocaition"></a></p>
  
  <p>I want to be able for a user to add comments to a news item. The comment should have a reference to the user who made it. And  a news item should have a list of all its comments.</p>
  
  <p>Domain Classes:</p>
  
  <pre><code>class User {
      String nickName
      String password
      Date dateCreated
      static hasMany = [users : User, comments : Comment]
      static hasOne = [profile : Profile]
      //static belongsTo = [comments : Comment]
  
      static constraints = {
          profile nullable: true
      }
  }
  
  class News {
  
      String webTitle
      String webPublicationDate;
      String trailText;
      String webUrl;
      String thumbnail;
      String webId;
      static hasMany = [tags : Tag, comments  : Comment]
  
      static constraints = {
      }
  }
  
  class Comment {
      //static belongsTo = [news : News, user : User]
      String content
      int likes
      int disLikes
      Date lastUpdated
      static hasOne = [user: User, news:  News]
  
      static constraints = {
      }
  }
  </code></pre>
  
  <p>IntegrationTests include: </p>
  
  <pre><code> void "A user can add to a post's comments"(){
      given: "An existing user"
      def newUser = new User(nickName: 'nickName', password: 'password').save(failOnError: true, flush : true)
  
      and: "A comment and a news"
      def news = new NewsItem(webTitle: 'I Love Hillary', webPublicationDate: new Date(),
              trailText: 'Hillary can change America', webUrl: 'http:google.com', webId: '4', thumbnail: 'image')
  
      when: 'A user adds comment to post'
      def comm = new Comment(content: "Hillary cant be president", user: newUser, newsItem: news)
      newUser.addToComments(comm)
      news.addToComments(comm)
  
      then: "NewsItem must have some comments"
      news.comments.size() == 1
      news.comments[0].user == newUser
      newUser.comments.size() == 1
      comm.user == newUser
      news.comments != null
  }
  </code></pre>
  
  <p>Any help will be appreciated</p>