Gorm Domain relationship

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Gorm Domain relationship

dchievo
This post has NOT been accepted by the mailing list yet.
Hello,

  Example:  I have two MySql tables.

Table: country
Columns:
Code char(3) PK
Name char(52)

Table: countrylanguage
Columns:
CountryCode char(3) PK
Language char(30) PK

here's an example of both tables.  the pk is the Code in Country and CountryCode in Countrylanguage.

Country table
# Code, Name,
'ABW', 'Aruba'


Countrylanguage table
CountryCode Language
'ABW', 'Dutch'
'ABW', 'English'
'ABW', 'Papiamento'


Here's my domains:

class Country {
    String id
    String name

    static hasMany = [languages: Countrylanguage]
    static fetchMode = [languages: 'eager']

    static mapping = {
        table 'Country'
        version false

        id column: 'Code', generator: 'assigned'//, params:[assigned:'ABW']
        name column: 'Name'
        code column: 'Code'
    }

    static constraints = {
    }
}


class Countrylanguage {
    String id
    String language

    static belongsTo = [country: Country]

    static mapping = {
        // map legacy mysql dB table
        table 'Countrylanguage'

        version false
        id column: 'CountryCode', generator: 'assigned'
        language column: 'Language'
    }

    static constraints = {
    }
}

I can't get GORM to properly join the pk and fks, which would be the Code/CountryCode fields that are indicated as the IDs.  Any suggestions guys?  Thanks for your help.
Loading...