Let's say you have face and nose, and you want to get the nose based on a faceId.
The Grails 开发者_运维技巧user guide tells you how to use mapping = { fetch:join } in a domain class to eagerly fetch the nose in one query whenever you fetch the face.
But I don't want to eagerly fetch all the time. I just want to do on this particular case to use one query instead of two. Can this be done on a per-query basis? Is there some way to do something like: Face.get(faceId, [join:nose])?
Do you mean somthing link taht:
static fetchMode = [nose:'eager']
found here
Update:
You can solve the problem with a criteria query. Here you can set the fetch mode in the query:
import org.hibernate.FetchMode as FM
def c = MyDomain.createCriteria()
def results = c.list {
maxResults(10)
firstResult(50)
fetchMode("aRelationship", FM.EAGER)
}
精彩评论