"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Domain Classes/findAllBy.html" (14 Sep 2022, 64796 Bytes) of package /linux/www/grails-core-5.2.4.tar.gz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.4.tar.gz project site itself.

(Quick Reference)

findAllBy*

Purpose

Dynamic method that uses the properties of the domain class to create query method expressions that return all matching instances of the domain class

Examples

Given this domain class:

class Book {
    String title
    Date releaseDate
    String author
    Boolean paperback
}

The following are all possible:

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

results = Book.findAllByTitleAndAuthor("The Sum of All Fears", "Tom Clancy")

results = Book.findAllByReleaseDateBetween(firstDate, new Date())

results = Book.findAllByReleaseDateGreaterThanEquals(firstDate)

results = Book.findAllByTitleLike("%Hobbit%")

results = Book.findAllByTitleIlike("%Hobbit%") // ignore case

results = Book.findAllByTitleNotEqual("Harry Potter")

results = Book.findAllByReleaseDateIsNull()

results = Book.findAllByReleaseDateIsNotNull()

results = Book.findAllPaperbackByAuthor("Douglas Adams")

results = Book.findAllNotPaperbackByAuthor("Douglas Adams")

results = Book.findAllByAuthorInList(["Douglas Adams", "Hunter S. Thompson"])

Description

GORM supports the notion of Dynamic Finders. The findAllBy* method finds all the results for the given method expression.

Parameters:

  • metaParams - A Map containing pagination parameters max, order, offset and sort and metaParameters readOnly, timeout, fetchSize, and flushMode

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", order: "desc", offset: 100])

If no items meet the supplied criteria an empty list is returned.

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

  • LessThan

  • LessThanEquals

  • GreaterThan

  • GreaterThanEquals

  • Between

  • Like

  • Ilike (i.e. ignorecase like)

  • IsNotNull

  • IsNull

  • Not

  • NotEqual

  • And

  • Or

  • InList

These operator names can be considered keywords, and you will run into problems when querying domain classes that have one of these names as property names. For more information on dynamic finders refer to the user guide.