Grails
  1. Grails
  2. GRAILS-8821

Add "first" and "last" methods to GORM

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.1.1, 2.2-RC1
    • Component/s: Persistence
    • Labels:
      None

      Description

      We often need a sample instance from a domain class when trying some implementation on Grails console or shell.

      This is so often that most ORMs out there for Ruby and Python will provide a "first" and "last" methods (maybe with different names).

      Unless the order is specified in "order" mapping, "id" should be used for the "ORDER BY" SQL clause.

      Currently, I often need to write things like MyDomain.findByIdIsNotNull() when I want a single sample. It should be easier with MyDomain.first() or MyDomain.last().

        Activity

        Hide
        Ganesh Krishnan added a comment -

        This should not be "Major" or "Bug"

        Show
        Ganesh Krishnan added a comment - This should not be "Major" or "Bug"
        Hide
        Graeme Rocher added a comment -

        Should be easy to add to Grails Data project, Jeff you want to take this on?

        Show
        Graeme Rocher added a comment - Should be easy to add to Grails Data project, Jeff you want to take this on?
        Hide
        Donal Murtagh added a comment -

        Would be more useful if a parameter was added such that we could return first/last N, rather than just first/last 1. Currently I usually do this using a criteria such as

            order("start", "asc")
            maxResults(count)
        

        But a dynamic finder that does the same thing would be handier.

        Show
        Donal Murtagh added a comment - Would be more useful if a parameter was added such that we could return first/last N, rather than just first/last 1. Currently I usually do this using a criteria such as order( "start" , "asc" ) maxResults(count) But a dynamic finder that does the same thing would be handier.

          People

          • Assignee:
            Jeff Scott Brown
            Reporter:
            Rodrigo Rosenfeld Rosas
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development