"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Domain Classes/countBy.html" (14 Sep 2022, 61586 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)



Dynamic method that uses the properties of the domain class to query for the count of the number of matching records


Given the domain class Book:

class Book {
    String title
    Date releaseDate
    String author

The following are all possible:

def c = Book.countByTitle("The Shining")
c = Book.countByTitleAndAuthor("The Sum of All Fears", "Tom Clancy")
c = Book.countByReleaseDateBetween(firstDate, new Date())
c = Book.countByReleaseDateGreaterThanEquals(firstDate)
c = Book.countByTitleLike("%Hobbit%")
c = Book.countByTitleNotEqual("Harry Potter")
c = Book.countByReleaseDateIsNull()
c = Book.countByReleaseDateIsNotNull()


GORM supports the notion of Dynamic Finders. The countBy* method counts the number of records for the given expression

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

  • Equal

  • NotEqual

  • And

  • Or

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