I want to create a domain object in different data sources based on a condition but when we instantiate a new object like new Foo().save()
there is no way to set which data source it will be done.
I've also noticed that if I do new Foo().dataSource2.save()
it still saves in default (unnamed) data source in addition to dataSource2
. How can we instantiate object only in one data source and save only in there?
I'm using grails 2.4.3
.
Edit: To make it clear. I want to dynamically pick which data source to create the user in during runtime.
It seems new Foo().dataSource2.save()
will not try to save it in the unnamed data source at a later point. This solution actually works.