We have two datasources in our grails project (master and slave) and we would like to have all our domain classes on both datasources. So we are trying to configure dynamically the static mapping closure by adding this code:
datasources(['DEFAULT', 'readonly'])
Let's say we have this domain class:
class Book {
String name
static mapping = {
sort 'name'
}
}
I would like to dynamically add code to the existing static mapping closure so the results would be:
class Book {
String name
static mapping = {
sort 'name'
datasources(['DEFAULT', 'readonly'])
}
}
I know I can use datasource 'ALL' but what I really want to know is how to add code to every existing static mapping in all domain classes.
And what about plugins with their own tables? I need to set datasource 'ALL' as default config or dynamically inject the code.