Parse.com按查询分组的数据

时间:2015-08-11 03:37:52

标签: database-design parse-platform nosql

需要一些数据设计方面的帮助

我有一个名为打印机的班级,他们有一个组织编号。我还有另一个叫做建筑的课程。打印机可以分组在建筑物下。我也有属于组织的用户。所以目前有以下数据结构

Organization name, organization number 
Building Name, building location, organization number 
Printer, printer details, organization number, building 
User, user name, organization number 
Message, messageID, urgency, pointer to printer

用户属于某个组织。建筑物也属于一个组织。
以下场景的最佳方法是什么 -
当用户登录时,如果任何打印机有紧急消息,他会看到所有建筑物的图标显示为红色。选择建筑物将向他显示所有打印机。

我是否需要进行多次解析查询?

1 个答案:

答案 0 :(得分:1)

试试这个,它可以通过查找打印机状态在一次调用中完成,然后您将决定从返回的对象中获取哪些数据。

//Set query to look for buildings and printers
    var query = new Parse.Query("buildings");
    query.equalTo("orgId",currentUserOrgId); //Check this line, apply your ID names

    var query2 = new Parse.Query("printers");

    var mainQuery = Parse.Query.and(query,query2);

    mainQuery.find({
        success: function(results) {
        alert("Successfully retrieved " + results.length + " objects.");

            // Do something with the returned Parse.Object values
        for (var i = 0; i < results.length; i++) {
            //Grab all building names, printers and messages etc here
            var object = results[i];
            alert(object.id + ' - ' + object.get('printerName')); 
            //get the values you need this way        
            if (object.get('urgency') == "urgent"){
                //add to an array of urgent printers with the pointer as well
            }
            //Add more logic here to sort through the class objects and store the data you need for your application
    }
  },
  error: function(error) {
    alert("Error: " + error.code + " " + error.message);
  }
});