Reputation: 1116
I have a Column as Array where I'm storing data with a pointer to _User entity:
[{
"score": 500,
"user":{
"__type":"Pointer",
"className":"_User",
"objectId":"b80TtUfOwH"
}
}, {
"score": 1000,
"user":{
"__type":"Pointer",
"className":"_User",
"objectId":"b80TtRdaw"
}
}]
I want to retrieve the entire array as an include with user property filled (table is Team and members is the Array column):
var query = new Parse.Query("Team");
query.include("members");
query.include("members.user");
I've tried those includes and the User is being detected but is not filled.
Is it possible to do that in one query?, how would it be?
I want to make use of Array Column (without an array pointer) because it wont be more than 10 and I want only one query.
Upvotes: 1
Views: 1549
Reputation: 62686
EDIT now that I understand the problem... The objects in the array are not pointers. Containing a pointer is not the same as being a pointer. No clever formulation of include
will work to fetch the user.
What to do? Teams have members who are people. That's a fairly universal fact, so I would suggest changing the members property to be an array of actual pointers. With that, this suggestion from my first edit will work, though, I think you knew this already...
var query = new Parse.Query("Team");
query.include("members");
query.find().then(function(teams) {
// teams will contain fully fetched users in the members property
});
But where should that other data in the array objects go? It depends on the meaning of that data. Does the data really belong to the relationship between the team and member? (A good example of something that might is a pro player's contract with a team). "Score" doesn't sound like such a thing. I'd find someplace else to put it (like in an object that records games played).
In general, when ClassA is related to ClassB (Team -> User for you), there are three places for attributes: on each class and on the relationship between them. If an attribute really must belong to the relationship, then you'll need a ClassC, which will carry that attribute.
One more thing: even in the case of an attribute that really belongs to a relation, you can often cheat it into the target class (ClassB). For example, a pro player's contract might belong to his/her relationship with their team, but if they are under contract to only one team at a time, you can cheat a little and attach this to the player.
Upvotes: 1
Reputation: 119031
If what you have tried doesn't work then I expect it isn't possible.
The alternative is to do it in cloud code where you can quickly fetch all of the nested content and format it into a single response.
Upvotes: 1