7.2.2 Composition in GORM 3.1.7

See the light - agile, industrial strength, rapid web application development made easy

(Quick Reference) # 7.2.2 Composition in GORM - Reference Documentation Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari Version: 3.1.7 ## 7.2.2 Composition in GORM As well as association, Grails supports the notion of composition. In this case instead of mapping classes onto separate tables a class can be "embedded" within the current table. For example:

    class Person {
        Address homeAddress
        Address workAddress
        static embedded = ['homeAddress', 'workAddress']
    }class Address {
        String number
        String code
    }
The resulting mapping would looking like this: If you define the `Address` class in a separate Groovy file in the `grails-app/domain` directory you will also get an `address` table. If you don't want this to happen use Groovy's ability to define multiple classes per file and include the `Address` class below the `Person` class in the `grails-app/domain/Person.groovy` file | Quick Reference (hide)