title: Grails not setting database up as expected
body: <p>Hi this have been going on for several months now and I have lost all hope.</p>
  
  <p>I have 3 domains in question.</p>
  
  <p>Product which is made up of Components, each Component can have alternative products.</p>
  
  <p>Here are my models:</p>
  
  <p>Product:</p>
  
  <pre><code> class Product {
       String name
       String comments
       static hasMany = [components:Components]
   } 
  </code></pre>
  
  <p>Component:</p>
  
  <pre><code> class Components {
      Product product
      static hasMany = [alternatives:Alternatives]
   }
  </code></pre>
  
  <p>Alternatives:</p>
  
  <pre><code>class Alternatives {
      Product product
  }
  </code></pre>
  
  <p>To populate this I am parsing an excel Spreadsheet here is the code that does it:</p>
  
  <pre><code>Product st = new Product(
      name: row.getCell(0).getStringCellValue().toUpperCase(),
      comments: "test"
  )
  row.getCell(10).getStringCellValue().split("[|]").each {
      Product pro = Product.findByName(it.toUpperCase())
      if(pro) {
          Components c =  new Components(product: pro).save(flush:true)
          s.add(c)
  
          // Does not work
          //st.addToComponents(c)
      }
  }
  st.save(flush:true,failOnError:true)
  </code></pre>
  
  <p>This does not create a table in the database called product_components. this is what I would expect.
  When I try and use addTo the component has a product instance associated with it, the product instance is then changed to the st product instance which I am trying to save it to.</p>
  
  <p>I hope that makes sense. </p>
  
  <p>I have found out that it is mapping the product in the Components domain as the component in the Product domain.</p>
  
  <p>I am now assuming that using mapped by in the Product table may fix it </p>
  
  <pre><code>static MappedBy = [components : //do something here ]
  </code></pre>
  
  <p>Found the answer see bellow:</p>
  
  <p>I had to add the following in my Product domain.</p>
  
  <pre><code>  static mappedBy = {components joinTable: [name:'product_components',
                      column:'COMPONENTS_ID',
                      key: 'PRODUCT_ID']}
  </code></pre>
  
  <p>and change the name of product to part_of in my Components domain.</p>