Is this really any or only a specific subset of classes? I believe that you will have several more domain classes that are not directly related to the user.
If so, you can create a class or UserAsset interface with belongsTo=[user: User] prop and inherit / implement it.
Then find all the domain classes that implement it and query each with clazz.findByUser() , for example:
GrailsClass[] classes = grailsApplication.getArtefacts('Domain') GrailsClass[] userAssetClasses = classes.clazz.findAll { UserAsset.class.isAssignableFrom(it) } List<UserAsset> allUserAssets = userAssetClasses.clazz*.findAllByUser(myUser).flatten()
edit . If we say M: M, it changes only the last line, a request for userAssetClasses requested.
UserAsset will have the hasMany=[users:User] property.
how
List<UserAsset> allUserAssets = userAssetClasses.clazz.collect{ Class domainClass -> it.withCriteria { users { eq('id', myUser.id) } } }.flatten()
source share