One of my fields for PFUser's is "ratingObject", a pointer to another class which has one column: "favouriteNumber". This keeps track of how many users follow this particular user. FavouriteNumber is just a number. I wanted to add this column directly to the PFUser row, however the app was crashing when I tried to increment this value from another user's account. Specifically when calling from user A:
userB.incrementKey("favouriteNumberInPFUser", byValue: 1)
userB.saveInBackground()
So I ended up creating this other class and adding a pointer to PFUser. However I need to perform a PFQuery taking into account this value. If it was in PFUser, no problem. But since it is in this other class, I can't really access it. I tried this:
var query2 = PFUser.query()
query2?.includeKey("ratingObject")
query2!.addDescendingOrder("ratingObject.favouriteNumber")
but it gives this error: [Error]: -ratingObject.favouriteNumber is not a valid order key (Code: 105, Version: 1.7.4)
It should be a number on the user, and it can be if you update it from cloud code. This could either be an explicit function, or it could be a save hook if the current user is modified when they favourite another user.
Related
I have created a PFObject called UserDataTable which stores information like username, password, Name, emailID, age, city, state, etc. of the user.
I am not sure how to authenticate the user to server using PFObject but can do so using PFUsers(). I know that PFUsers is a sub-class of PFObject so there must be a way to access those properties using my PFObject.
Can anyone help me out with the same. I am using SWIFT for coding.
let UserDataBase = PFObject(className: "UserDataBase")
UserDataBase["userId"] = "aamirdbx"
UserDataBase["userName"] = "Aamir Bilal"
UserDataBase["userPassword"] = "pass"
UserDataBase["userEmailId"] = "aamirdbx#gmail.com"
I would like to Sign In using information in this UserDataBase which is a PFObject.
I know how we can do the same using PFUser() but I want to avoid using a bunch of different Objects.
You should be using PFUser for this no matter what. PFUser already has all the built in authentication protocols, session tokens, security and ACL built in for you, which as someone who is just getting started is not something you want to try and manage yourself. You can add extra information to your Parse User class if you need to store additional information, or you can create another table, and have a pointer in your user class to the data in the other table, but for your sake and your user's sake, please don't try to handle this yourself.
After that chunk of code you should call userDataBase.saveInBackground() or saveInBackgroundWithBlock but then you would have to do a lot more coding every time they log in to authenticate and sync objects with the user etc. The included PFUser subclass does a lot of the heavy lifting for you, plus you can add properties to the user subclass so that would probably be a better option.
so i am working on an app where user can follow each other.. i've been working on it and tried to set the followers in a class Followers and saved the PFUser.currentUser().objectId in the column follower and the objectId of the user in column user i am saving the objectId as Strings. Is this the best possible way or we can use something else to achieve the require things easily. Help me out here please. Thanks for your time..
You should set the column type to Pointer and then have each Pointer be of type User so that you can link directly to the User objects and query on them.
I am working on an iOS app, running on Parse(backend).
I am having problems with accessing the contents of another class from a query I made.
So I have this table. Let's call it "Contests". it has the following data:
name,
date start,
date end,
pointer to organization table (the objectid)
And then the organization table:
name,
number of Facebook likes,
I want to be able to access the name of the organization and every other detail a certain contest has. Will I have to put a query inside another query, slight problem with that is that the queries require waiting time and it accomplishes it in the background. So I have:
findInBackground() {
findInBackground() {
}
}
Is there any better way to do this? Also I am getting multiple objects at the same time.
You need to do a query on your Contest table with whatever requirements you have but then add an includeKey call:
var query = PFQuery(className:"Contests")
//...Other query requirements
query.includeKey("organization")
query.findObjectsInBackgroundWithBlock {
}
includeKey will force fetch of the organization along with the contest details in 1 query.
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.
How do i get the id for accessing user info by (Hashie::Mash)user(id) method of the instagram API or accessing his/her location by (Hashie::Mash)location(id)?
I am using rails for my project.
You can search for a user to get his/her id, e.g:
shaynesids = Instagram.user_search("Shayne Sweeney")
That will give you all the ids on an array of user matching Shayne Sweeny (hopefully just one), then you can use it with user(id), like this:
myuser = Instagram.user(shaynesids.first)
Note: In here I'm assuming that the search it's gonna return at least one result, you will need to be careful in your code to account for errors, because it could return an empty array.