woodmawa opened a new issue, #14626:
URL: https://github.com/apache/grails-core/issues/14626

   i had a problem i posted on stackoverflow relating to the documentation and 
what was happening - see 
http://stackoverflow.com/questions/42229853/grails-v3-2-6-gorm-embedded-class-in-same-domain-class-groovy-creates-dummy-db/42322967#42322967
   
   in essence using grails 3.2.5 and now 3.2.6, if you create a domain class 
and in the same file create a embedded reference to 'subClass' you want to 
embed, then gorm is creating 'both' tables (parent, and embedded ) in DB and 
this led to set of tests that didnt work as expected.  
   
   when i dug in an looked its because if you save the embedded ref before the 
parent it goes in its own table and is then saved again in the embedded columns 
in the parent table.
   
   I managed (i think ) to fix this by having to declare the embedded class as 
static sub class of the parent and then you only get the single DB table.  
however this is not what the documentation says.  
   
   so the new approach shown below ensures that only one table is created.  The 
previous code had the GeoLocation class sitting below the venue in the same 
groovy file - but that generates two tables.  
   
   Either the documentation in section 5.2 is wrong /unclear, or the code isnt 
doing what the docs say.
   
   I hope that's clear.    If you need to see the code tree on Git its here 
   
   [coffeeShopApp](https://github.com/woodmawa/coffeeShopApp)
   
   ```
   class Venue implements Serializable {
   
       String name
       LocalDate dateCreated
       LocalDate lastVisited
       LocalDate lastUpdated
       GeoAddress location
       Collection posts
   
       //static hasOne = [location:GeoAddress]   //, temp:TempLocation
       static hasMany = [posts:Post]           //but doesn't really own thats 
with user
       static embedded =['location']
   
       static constraints = {
           lastVisited nullable:true
           location    nullable:true, unique:true
           posts       nullable:true
       }
       static mapping = {
           location cascade: "all-delete-orphan", lazy:false, unique:true  
//eager fetch strategy
           posts    sorted: "desc", cascade:"save-update"
   
           //comment out for now
           //posts joinTable: [name:"venue_posts", key:"venue_id", 
column:"posts", type:Post]
       }
   
       static class GeoAddress {
   
           String addressLine1
           String addressLine2
           String addressLine3
           String town
           String county
           String country = "UK"
           String postcode
   
           //adds addTo/removeFrom methods to venue
           static belongsTo = Venue
   
           static constraints = {
               addressLine1 nullable:true
               addressLine2 nullable:true
               addressLine3 nullable:true
               town         nullable:true
               county       nullable:true
               country      nullable:true
               postcode     nullable:true
           }
       }
   } 
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to