How do I save Parse.User data as pointer of arrays

954 views Asked by At

Hi I'm using Parse Javascript API.

I was trying to save user objects as pointer of user array.

But result is

[{"__type":"Pointer","className":"_User","objectId":"a85SoYwEiE"}]

Could you advising me?

Here's my code

if (mentions.length > 0) {

    var query = new Parse.Query(Parse.User);
    query.containedIn("username", mentions);

    query.find().then(function(users) {

    // each of results will only have the selected fields available.
    var MensionNoti = Parse.Object.extend("Notification");
    var mentionNoti = new MensionNoti();

    //set by as CurrentUser
    mentionNoti.set("notiBy", commentBy);

    for (var i = 0; i < users.length; i++) {
        // This does not require a network access.
        //var user = users[i];
        var userPointer = Parse.User.createWithoutData(users[i].id) ;
        mentionNoti.addUnique("notiArray", userPointer);
    }

    //mentionNoti.set("notiArray", users);
    mentionNoti.set("type", "mention");
    //set Comment
    mentionNoti.set("messageText", comments);

    mentionNoti.set("checked", false);
    mentionNoti.set("postObj", results);
    mentionNoti.save();
    });
}
1

There are 1 answers

0
Ye Min Htut On BEST ANSWER

Try this. I haven't tested the code but technically, it should work.

var userArray = [];
for (var i = 0; i < users.length; i++) {
   // This does not require a network access.
   var userPointer = Parse.User.createWithoutData(users[i].id) ;
   userArray[i] = userPointer;
}
mentionNoti.addUnique("notiArray", userArray);
...
mentionNoti.save();

Hope this helps :)