I have several relationships on Parse and I am attempting to perform a query to pull back all the data.
Classes:
I would like to query for all Equipment whose EquipmentType is equalTo "robot" and have the result include all EquipmentAttributes and Notifications associated.
I have been unsuccessful in finding a way to perform this query. I have tried the following:
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);
}
});
});
But this will only bring back Equipment that has EquipmentAttributes and misses all of the ones that don't.
How can I pull back all the information and return it in a single JSON response?
Thanks...
Unless you've created a two-way relationship between Equipment
and EquipmentAttribute
you'll have to do two queries and manually assemble the results.
If you had an attributes
property on Equipment
of type Array then you could just use equipmentQ.include("attributes");
and not bother with the query against EquipmentAttribute
.
If needed I can provide a sample of either solution.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.