Grails
  1. Grails
  2. GRAILS-8072

Improve default toString() output for domain classes

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-M2
    • Fix Version/s: 2.1.4, 2.2.1, 2.3-M1
    • Component/s: None
    • Labels:
      None

      Description

      The default toString() output for domain classes is "[Class: id]". If the object hasn't been saved yet, then id is null and you get "[Class: null]". This is confusing because it makes it seems that the domain instance itself is null.

      I recommend that if the ID is null, we generate something like "[Class: (unsaved)]" or "[Class: (no id)]".

        Activity

        Hide
        Brian Saville added a comment -

        I've been bit by this bug as well, voted!

        Show
        Brian Saville added a comment - I've been bit by this bug as well, voted!
        Hide
        Eduardo Goncalves added a comment -

        I agree with the recommendation. How can I help fix it?

        Show
        Eduardo Goncalves added a comment - I agree with the recommendation. How can I help fix it?
        Show
        Graeme Rocher added a comment - The relevant code can be found here: https://github.com/grails/grails-core/blob/master/grails-core/src/main/groovy/org/codehaus/groovy/grails/compiler/injection/DefaultGrailsDomainClassInjector.java#L190 Contributions welcome

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            Peter Ledbrook
          • Votes:
            12 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Last Reviewed:

              Development