简体   繁体   中英

updating many users at once in parse

I'd like to update user's column which presents related posts that the user might like, my code is like that:

let users = query.findObjects() as [PFUser]

    for user in users{
            let rel = user.relationForKey("posts")
            rel.addObject(post, forKey: "relatedPosts")
            rel.saveInBackground()
        }

I really don't know why, but I tried to do that in many versions (not only by relation, also by arrays and other methods) and it always updates just one user (the one who logged in).. how can I get this done?

You can't update user that is not currently authenticated in your app.

The way I see it you have 2 options:

1) You can set some Cloud Code to run using the master key, so it can modify users.

2) You can add a new custom column to your Parse User class that will link to another class DB that has the related posts for the user. take a look here: Parse.com Relations Guide

I would choose #2.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM