简体   繁体   中英

Is it possible to save a new Grails domain instance without fetching referenced domains?

I have a user_id (for User domain) and want to save a new instance of another domain referencing that User without fetching the User instance. Is this possible? I tried:

User user = User.load(user_id)
new Action(user: user, foo: "bar").save()

This fetches the user. I also tried:

User user = new User(id: user_id)
new Action(user: user, foo: "bar").save()

This also fetches the user.

I need this to work for performance reasons and don't want to have to insert the rows using JDBC if I can avoid that. I am using Grails 3.0.1.

This is dark side of ORM and you won't be able to do it without bypassing GORM. ORM only knows about Objects and Classes. Tables, columns and other database stuffs are not in ORM's dictionary. The other option is to create a service for this and in this service use POGO (groovy version of POJO) to interact with databases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM