1

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.

2
  • what about 2 , parallel arrays (score, user are correlated by index value). then, with pure array of pointer ( class _User ) you can get them all via an extra 'fetch'. Commented Dec 31, 2015 at 15:13
  • I thought about that but I would also need to filter Teams where "I'm admin" (which is also another field isAdmin). And for the query where I'm filtering by User Id I cannot know if in the other array (at same pos) has isAdmin = true. I'm starting to think the best way is to create a second table "Member" and work in there with relations instead of an Array Commented Dec 31, 2015 at 18:46

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

5 Comments

My problem is there is more info in each object of the array. It's not just an array of Pointers to User, it also has more info which is not related to the user but the member where the user is attached to. The way of your example would work if it's just an array of User Pointers, any ideas?. thanks!
I see. I should have understood that from your question. Please see edit
yeah "score" was as example, in reality there will be displayName and isAdmin which are attrs that belong to the relation between a team and a user (as a member). I was trying to avoid the creation of a new class for the sake of simplicity since there won't be a more than 10 members per team and I wanted to be a fast fetch and simpler save. thanks for your help!
sure, though note my last paragraph. if team membership is only one at a time, you could put displayName and admin on the user.
yeah, but a user can be in several teams so it could have more that one displayName and be an admin in some but not all the teams

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.