Grails
  1. Grails
  2. GRAILS-6551

hasOne results in eager fetching of association

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.3.3
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      If I have the following domain model:

      class Author {
          String name
          
          static hasOne = [ location: Location ]
      }
      
      class Location {
          String city
      }
      

      then when I execute this code:

      Author.list().each { a ->
          println a.location.city
      }
      

      I find that the location instances are all loaded up front with separate SELECTs. In other words, they're loaded eagerly. Explicitly specifying the relationship as lazy: true has no effect.

      Perhaps this behaviour is expected, but it seems strange to me.

        Issue Links

          Activity

            People

            • Assignee:
              Jeff Scott Brown
              Reporter:
              Peter Ledbrook
            • Votes:
              3 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development