(Quick Reference)

findAllBy*

Purpose

Dynamic method that uses the properties of the domain class to allow the creation of Grails query method expressions that return all instances of the domain class

Examples

Given the domain class Book:

class Book {
   Long id
   Long version
   String title
   Date releaseDate
   String author
}

Examples:

def results = Book.findAllByTitle("The Shining", [max:10, sort:"-title", offset:100] )
results = Book.findAllByTitleAndAuthor("The Sum of All Fears", "Tom Clancy")
results = Book.findAllByReleaseDateBetween(firstDate, new Date())
results = Book.findAllByReleaseDateGreaterThanEquals(firstDate)
results = Book.findAllByTitleNotEqual("Harry Potter")
results = Book.findAllByReleaseDateIsNull()
results = Book.findAllByReleaseDateIsNotNull()

Description

Parameters:

  • queryParams - A Map containing parameters max, offset, sort and validate (to turn off morphia mapping validation)

Pagination and sorting parameters can be used as the last argument to a dynamic method:

def results = Book.findAllByTitle("The Shining", [max:10, sort:"title", offset:100] )

The following operator names can be used within the respective dynamic methods:

  • LessThan
  • LessThanEquals
  • GreaterThan
  • GreaterThanEquals
  • Between
  • IsNotNull
  • IsNull
  • Equal
  • NotEqual
  • And

The above operator names can be considered keywords, and you will run into problems when querying domain classes that have one of these names used as property names.