1

In my present project I need to use 2 databases, one for master data and the other for client data.As of now we are using single db but we planned to split it into 2 databases (master db & client db).

We have association between client and master db on domain classes level. I tried grails 2.X multiple data-source option, but association is not possible. If any one worked on this scenario suggest me the best approach.

We tend to use single master db for all client instances.

defectus
  • 1,947
  • 2
  • 16
  • 21
snaredla
  • 11
  • 3

1 Answers1

0

I based my solution on this answer:

class ClassB {
    Long classAId

    static constraints = {
        classAId nullable: true
    }

    static mapping = {
        datasource 'other'
    }

    static transients = ['classA']

    ClassA getClassA(){
        classAId ? ClassA.get(classAId) : null
    }

    ClassB(classAId){
        def test = ClassA.get(classAId)
        classAId = test ? test.id : null
    }
}

maybe it's not pretty but it's working.

Community
  • 1
  • 1
Michal_Szulc
  • 4,097
  • 6
  • 32
  • 59