Using ArgoUML, I very rapidly produced this trivial representation of the couple of Domain classes (Person, Store, Product) as well as their associations. UML Model

I am battling using the implementation from the associations. Below was my primary method for the individual domain, however it appears that i'm missing something important.

class PersonToPerson 

    static belongsTo = [ Person ]



class Person 

Edit: up-to-date question for clearness


After thinking around the problem I believe I've got a better method to request the question(s). Within the implementation of PersonToPerson above I've the relation like a simple string. I would like the consumer to have the ability to choose from a listing of unique relations, that are defined within the constraints, for that string value for PersonToPerson. So this can lead to the questions...

  1. Should personToPerson and personToStore be consolidated into one listing of type Relationship? Or whenever they stay independent lists as proven?
  2. What's the mechanism to permit the consumer to include new values towards the relation constraint?

1) Domain model

Keep the code simple. Don't create generic data model. It's method to hell. Whenever you personToPerson and personToStore keep separate, it's much simpler to follow along with your code.

Really recommended solution causes it to be easy to access relations as consolidated and independent list concurrently.

With this problem I'd use inheritance feature in GORM.

Your classes would seem like this:

class Person title

    static hasMany = [personToPerson:PersonToPerson,

                      personToProduct:PersonToProduct,

                      personToStore:PersonToStore]

    static mappedBy = [personToPerson:"from"]



class Product

class Relationship

class Store

class PersonToPerson stretches Relationship

    static belongsTo = [ from:Person ]



class PersonToProduct stretches Relationship

    static belongsTo = [ person:Person ]



class PersonToStore stretches Relationship

    static belongsTo = [ person:Person ]



DB schema for Person, Product and Store is usual. However for Relational domain names seem like this:

Relationship

Area      Type         Null Default

id         bigint(20)   No

version    bigint(20)   No

note       varchar(255) No

class      varchar(255) No

person_id  bigint(20)   Yes  NULL

product_id bigint(20)   Yes  NULL

relation   varchar(8)   Yes  NULL

from_id    bigint(20)   Yes  NULL

to_id      bigint(20)   Yes  NULL

store_id   bigint(20)   Yes  NULL

Relationship domain allows to gain access to all relational domain throw one domain.

2) Constraint

Just switch inList to validator. Than you are able to store constrain in file or DB. See documentation or file example.

Example how you can store constraint values in DB. First produce a domain object.

class Constraintitle

    String type



Compared to domain class looks:

class PersonToPerson stretches Relationshiptitle

             return list.consists of(val)

         )

    

    static belongsTo = [ from:Person ]