繁体   English   中英

解析云代码加载一对多关系

[英]Parse Cloud Code loading a to-Many relationship

我在Parse上有几种关系,我试图执行查询以拉回所有数据。

类:

  • 设备
  • 设备类型
  • 设备属性
  • 通知
  • NotificationType
  • 设备具有设备类型
  • 设备具有许多设备属性
  • 设备有很多通知
  • 通知具有NotificationType

我想查询所有EquipmentType等于equalTo“ robot”的设备,并使其结果包含所有与之关联的EquipmentAttributes和Notifications。

我一直没有找到执行此查询的方法。 我尝试了以下方法:

Parse.Cloud.define("getFleetList", function(request, response) {
  var typeQ = new Parse.Query("EquipmentType");
  typeQ.equalTo("code", "robot");

  var equipmentQ = new Parse.Query("Equipment");
  equipmentQ.include("type");
  equipmentQ.matchesQuery("type", typeQ);

  var attribQ = new Parse.Query("EquipmentAttribute");
  attribQ.include("equipment");
  attribQ.matchesQuery("equipment", equipmentQ);
  attribQ.find({
    success: function(results) {
      response.success(results);
    },
    error: function(error) {
      response.error("lookup failed: code:" + error.code + " message:" + error.message);
    }
  });
});

但这只会带回具有EquipmentAttributes的Equipment,而错过所有不具有的那个。

如何获取所有信息并在单个JSON响应中返回?

谢谢...

除非您在EquipmentEquipmentAttribute之间创建了双向关系,否则您将必须执行两个查询并手动组合结果。

如果您在Array类型的Equipment上具有attributes属性,则可以只使用equipmentQ.include("attributes"); 而不必理会针对EquipmentAttribute的查询。

如果需要,我可以提供两种解决方案的样本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM