belongsTo array plus hasMany ownership

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

belongsTo array plus hasMany ownership

I have a class that both has got a many-to-many relationship (with the other side being the owner) as well as a n:1 relationship.

I could not find an answer on the web how to put the ownership into the belongsTo clause.

This is the code:

class PanelType {
    static hasMany = [elements: LabValueType]

class LabValueType {

    static belongsTo = [labUnit: LabUnit]
    // This is what would be needed to have a bidirectinal n:m relationship
    // belongsTo = PanelType
    // static hasMany = [panelTypes: PanelType]

If I leave it like this, the application builds the database correctly, but I won't be able to navigate from LabValueType to PanelType.

I found one answer (from 2008!) that said I should write:
static belongsTo = [PanelType, LabUnit]
BUT this way, the field lab_unit_id is not created in the database, so it does not seem to be correct.