tags:

views:

12

answers:

0

We have a couple of domains something like the following:

class Interceptor {
    static hasMany = [positions:Position]
}

class User {
    static hasMany = [positions:Position]
}

There is a procedure in our application where we are looping over a set of Users and we need to see if the User contains a position based on the Interceptor's positions. So our code is:

positions.each { position ->
    def list = User.findBoardMembersByPosition(board, position)
    // more stuff here
}

And the find method called on User is:

static findBoardMembersByPosition(board, position) {
   def list = User.findAllByBoard(board)

   def members = []
   list.each { member ->
      def positions = member.getPositions()
      if (positions.contains(position)) {
         members.add(member)
      }
  }

  return members
}

The position that is passed into the find method during the first iteration, doesn't have all it's data, due to lazy loading. This is normal. However, when the conains() method is called, it is failing because something is not triggering hibernate to go fetch the data for position so the comparison works correctly. To get around this we've made fetching eager for positions in the Interceptor class. I'm wondering if this is a bug or if this is normal behavior.

Thanks