Where queries are the preferred way to build more complex queries. They are type safe, expressive and lazily executed:
def query = Book.where {
title == 'The Stand'
}Note that no query is actually executed directly, instead the where(Closure) method returns an instance of DetachedCriteria.
Like an rx.Observable, the DetachedCriteria class can be subscribed to:
Book.where {
title == 'The Stand'
}
.subscribe { Book book ->
println "Title = ${book.title}"
}Alternatively you can execute one of the query methods to invoke the query and return an rx.Observable:
Book.where { title == 'The Stand' }
.list()
.subscribe { List<Book> books ->
for (Book book in books) {
println "Title = ${book.title}"
}
}For more information on the syntax of where queries see the relevant section in the GORM documentation.