var GraoController = function(di) {
  di.event.new('Instance created').success().present().log('info');
  di.controllers = this;

  this.processDataList = function(model, query){
    var dataList = { data: null,
                      filter: null,
                      sort: { field: '_id', type: '-'}, 
                      page: { skip: 0, limit: 10 }, 
                      status: { totality: 0, filtered: 0, listing: 0 } };
    if(query.data)
      dataList.data = JSON.parse(query.data);

    if(query.page)
      dataList.page = JSON.parse(query.page);

    if(query.status)
      dataList.status = JSON.parse(query.status);

    if(query.sort)
      dataList.sort = JSON.parse(query.sort);

    dataList.sort = "field "+(dataList.sort.type == '-' ? '-' : '')+dataList.sort.field;

    if(query.filter) {
      var realyFilter = false;
      dataList.filter = JSON.parse(query.filter, function(key, value){
        if(key.length <= 0)
          return value;

        if(!(model.schema.paths[key] && typeof model.schema.paths[key] === 'object'))
          return null;

        if(model.schema.paths[key].instance == 'String') {
          if(value.length > 0) {
            realyFilter = true;
            return new RegExp('.*'+value+'.*', "i");
          }
          else
            return "";
        }
      });
    }  

    return dataList;
  };

  di.controllers = di.loader.tryLoad(di.loader.loading('controller'), di, 'controllers');
};

module.exports = exports = GraoController;
@@ -812,39 +812,8 @@
 ) %7B%0A
-      var realyFilter = false;%0A
     
@@ -859,30 +859,49 @@
 lter
-, function(key, value)
+);%0A      for(var key in dataList.filter) 
 %7B%0A  
@@ -940,18 +940,14 @@
     
-return val
+contin
 ue;%0A
@@ -1047,20 +1047,18 @@
     
-return null;
+continue;%0A
 %0A%0A  
@@ -1127,21 +1127,36 @@
      if(
-value
+dataList.filter%5Bkey%5D
 .length 
@@ -1178,92 +1178,347 @@
     
-realyFilter = true;%0A            return new RegExp('.*'+value+'.*', %22i%22);%0A          %7D
+dataList.filter%5Bkey%5D = RegExp('.*'+dataList.filter%5Bkey%5D+'.*', %22i%22);%0A          %7D%0A          else%0A            dataList.filter%5Bkey%5D = %22%22;%0A        %7D else if(model.schema.tree%5Bkey%5D) %7B // ref%0A          if(model.schema.tree%5Bkey%5D instanceof Array && model.schema.tree%5Bkey%5D%5B0%5D.ref) %7B%0A            dataList.filter%5Bkey%5D = %7B $in: dataList.filter%5Bkey%5D %7D;
 %0A   
@@ -1527,37 +1527,134 @@
     
+ %7D
  else
-%0A            return %22%22;%0A
+ if(model.schema.tree%5Bkey%5D && model.schema.tree%5Bkey%5D.ref) %7B%0A            dataList.filter%5Bkey%5D = dataList.filter%5Bkey%5D;%0A  
     
@@ -1669,19 +1669,25 @@
     
-%7D);%0A
+  %7D%0A  
     %7D
+%0A
   
+  %7D
 %0A%0A  

Add refs support in GraoController