     @collection = args.collection
     unless @collection
       throw new Error('No collection provided when creating tree data')
+    @_setUpQueries(args)
   
   getChildren: (doc, args) ->
     args ?= {}
     # Search for root document if doc is undefined
     id = doc?._id ? null
-    children = @collection.find({parent: id}).fetch()
+    children = _.map _.keys(@_queries[id]?.children ? []), (childId) =>
+      @collection.findOne(childId)
     children.sort(@compareDocs)
-
     children
   
   hasChildren: (doc) -> @getChildren(doc).length == 0

  compareDocs: (docA, docB) ->
    if docA.name < docB.name then -1 else 1


class IdSet


    items = @collection
  @items = items

  @model = data.model ? new TreeModel(collection: @collection, template: @)
  @selection = new IdSet({exclusive: !settings.multiSelect})
  @check = new IdSet({exclusive: false})
  # Allow modifying the underlying logic of the tree model.
