Organise ActiveRecord model into a tree structure by the path enumeration model