title: Sort List of objects by id from a sting List
body: <p>I have a grails application with Java 7. In this I have a table for List and a table for Items in the table which is shown as below. It's a many to many relationship where List is the parent, and for Normalization I have List_Item class, so the normal functionality is working as expected.</p>
  
  <pre><code>Class Parent{
      static hasOne{list:List}    
  }
  
  Class List{
      ....
      static hasMany{item:Item}
      static hasOne{listOrder:ListOrder}
  }
  
  Class Item{
      Long id
      .....
  }
  </code></pre>
  
  <p>Now I have to store the order of the items in the list. So I created the following structure</p>
  
  <pre><code>Class ListOrder{
      Long id
      List list
      //Stores all the ids as a coma separated string in the necessary order
      String order
  }
  </code></pre>
  
  <p>So each time the order is changed, the ListOrder record is to be updated. </p>
  
  <p>Now I need a way to sort the items with the stored id Sting when I retrieve either List or the Parent classes. I was hoping to achieve this by a method in List domain object with name 'orderItems()', where when I call this method, the item parameter in List object, will be set to the sorted List object.</p>
  
  <p>The idea I have in mind looks similar to the following code</p>
  
  <pre><code>Class List{
      ....
      orderItems(){
          this.item = this.item.sort(this.itemOrder.order.split(','))
      }
      ....
  }
  </code></pre>
  
  <p>How can I achieve this, or is there a better way to achieve this? According to the requirement a List can contain over 100 items, so I opted not to store each items position individually.</p>