Grails
  1. Grails
  2. GRAILS-8973

hasMany mapping for 'eager' only returns first result when using findBy* gorm method

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 2.0.1, 2.0.2
    • Fix Version/s: None
    • Component/s: Persistence
    • Labels:
      None

      Description

      I have a one to many association mapped as:
      class Site {
      static hasMany = [subItems:SubItem]

      static fetchMode = [subItems: 'eager'] // not working in grails 2.0.1, 2.0.2

      static mapping =

      { cache true subItems cache: true sort id: "desc" }

      }

      class SubItem {
      String mkey
      String mvalue

      static belongsTo = [site:Site]

      static constraints =

      { mkey nullable: false, blank: false, maxSize: 255, matches: /[a-zA-Z0-9\.\-_]+/ mvalue shared:'longtext' }

      static mapping =

      { version false cache true }

      }

      performing:
      Site.findById(1)

      correctly returns site #1, but if site #1 has more than one subItem... only the first subItem is returned (using the fetchMode designation). If you remove fetchMode the items are fetched lazily with a subsequent query and all values are found.

      Seems due to the fact that the query being executed has a 'limit 1' at the end thereby returning only the first sub-item in the result-set rather than all sub items.

        Activity

        Hide
        Oliver Wahlen added a comment -

        I think this is related to GRAILS-8915.
        Same issue with n:m relation.

        Show
        Oliver Wahlen added a comment - I think this is related to GRAILS-8915 . Same issue with n:m relation.
        Hide
        John Hayward added a comment -

        Yes, it does look to be the same issue. Sorry I didn't catch that initially. Anyone can feel free to join the two bugs or simply remove this one.

        Show
        John Hayward added a comment - Yes, it does look to be the same issue. Sorry I didn't catch that initially. Anyone can feel free to join the two bugs or simply remove this one.

          People

          • Assignee:
            Unassigned
            Reporter:
            John Hayward
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development