2 Replies Latest reply on Sep 2, 2013 3:22 AM by Kutir Mobility

    What is the best way to order a property bag on integers stored as strings?

    Graham Bird

      I have data that has been synchronised as a PropertyBag through RhoConnect.

      There is a property called Position which was an integer value from the originating database.

      I wanted to write something like the following and have the ordering use the integer value of the Position property rather than the string value:

      AbortReason.find(:all, :conditions => {:Enabled => true}, :order => :Position, :orderdir => 'ASC')

       

      After a bit of research I was running into various solutions for Fixed Schema data, but could not find anything suitable for a PropertyBag.

       

      The only way I have found to achieve this is to use a sort call instead:

      @sortedReasons = AbortReason.find(:all, :conditions => {:Enabled => true})

      @sortedReasons.sort! { |a,b| a.Position.to_i <=> b.Position.to_i }

       

      I was wondering whether there was a suitable way of achieving the same thing in the find statement or if there is a better alternative to that shown above.

       

      Many thanks for any ideas,

      Graham Bird.