Array of Pointers?

Can I create a column as an array of pointers? If so, how?

Choosing the “Pointer” data type is a 1-to-1 data entry
Choosing “Array” data type seems to be string or number elements

Initially, I am just pre-populating some dummy data via the Dashboard to see how the dataset works within the overall app.

Or is there another approach I am not considering? The item would contain a small number of elements, max of 4 I would say, and rarely changes.

You can absolutely save an array of pointers however most times you should use a relation instead.

Here’s an example of how to save an array of pointers:

const user1 = new Parse.User(); = 'user-1';
const user2 = new Parse.User(); = 'user-2';
const object = new Parse.Object('SomeClass');
object.set('someField', [user1, user2]);

Using a relation would look like this:

const user1 = new Parse.User(); = 'user-1';
const user2 = new Parse.User(); = 'user-2';
const object = new Parse.Object('SomeClass');
const relation = object.relation('someRelation');
relation.add([user1, user2])
1 Like

Thanks - and I can see the concept.

Can I enter this directly through the Parse Dashboard? Maybe its a limitation?

I only seem able to define an array of strings…

You will just define it as an array. You can put whatever you want in it. If you’re trying to add the values directly from the dashboard you would create pointer objects like this:

    "__type": "Pointer",
    "className": "SomeClass",
    "objectId": "abc-123-xyz"
1 Like

If I might step in, I am trying to understand the benefit of pointers / relations. From what I tried in both cases there is no update done on the “pointing” object if I delete the “pointed-to” object. Therefore the “pointing” object has to be updated always with delete/insert of the “pointed-to”

Where is then the benefit of using a array of pointers instead of shorter array of objectIds?

I also do not find in the documentation ho Relations work under the hood and can only follow the recommendation of max 100 object in array or use relations otherwise. From what I understood the relations behaves kind of like a memory leak if the “pointed-to” document is deleted without updating the “pointing” one first.

1 Like

The benefit of an array of pointers (instead of array of objects ids) is making possible relation queries to be used later on.

HI @davimacedo , is there any way to query on pointers created on _User table?

here is my User Schema
Now I want to retrieve User which is associated with schoolId and want to delete that record after that.

I have already tried a couple of solutions like passing obj in equalTo query I also mentioned the code below. my mistake was Pointer keyword was in small case. this code works but is there any simple option to query on pointer like we do for other fields like the query.equalTo(‘name’, “abc”)

const obj = {"__type": “Pointer”, className: “schools”, “objectId”: schoolId};

    const mainQuery = new Parse.Query("_User");
    mainQuery.equalTo('schoolId', obj)
    return mainQuery.find()


@manish.yes does your schoolId field need to be an array? if this was a Pointer field, Im pretty sure the equalTo would work.

I believe mainQuery.equalTo('schoolId', schoolObject) should work.