My domain class looks like this :
class UserEvent {
User user
Event event
boolean isAttending
}
Generated database table looks has following columns:
[ID , EVENT_ID, USER_ID , IS_ATTENDING ]
I have Event object and only id of User object (user_id).
I want to create new UserEvent object with this data only, without loading User object, it may look something like this:
def userEvent = new UserEvent(user:['id':user_id],isAttending: true, event: event)
I’ve tried a lot of things but didn’t find the solution. I think it is definitely possible, since it is done in a similar way with params in controllers which contain only ids of associated objects:
def userEvent= new UserEvent(params)
I am looking forward to finding the solution. Thank you.
When you say “without loading the User object”, you can do this:
Unlike
get, theloadmethod does not hit the database. Instead, it creates a proxy object that only fetches its data from the database the first time a non-idproperty is accessed.