0

I want to query the user data based on the profile you are on in my app. As of now my query just gets all the posts not just the user that the profile belongs too.

"Drives" is the class name of the user posts.

 post.removeAll(keepCapacity: false)
    var findTimelineData:PFQuery = PFQuery(className:"Drives")
    findTimelineData.findObjectsInBackgroundWithBlock
        {
            (objects:[AnyObject]! , error:NSError!) -> Void in
            if error == nil
            {
                self.post = objects.reverse() as [PFObject]
                self.table.reloadData()
            }
    }
2
  • Give some more information about your "Drives" class, what columns are there, which one contains a pointer to the user? Commented Dec 30, 2014 at 7:33
  • @TimothyWalters so the Drives class has the object ID the pointer to the driver and all the textfields which are properties of the post (each textfield has its own column) Commented Dec 30, 2014 at 8:57

1 Answer 1

1
post.removeAll(keepCapacity: false)
var findTimelineData:PFQuery = PFQuery(className:"Drives")

//Add the next line
findTimelineData.whereKey("YOUR_COLUMN_NAME_WHERE_THE_USERS_ARE_STORED", equalTo: "THE_NAME_OF_THE_USER")


findTimelineData.findObjectsInBackgroundWithBlock
    {
        (objects:[AnyObject]! , error:NSError!) -> Void in
        if error == nil
        {
            self.post = objects.reverse() as [PFObject]
            self.table.reloadData()
        }
}

Or instead you can choose any whereKey... function, listed as here: https://parse.com/docs/ios/api/Classes/PFQuery.html#//api/name/whereKey:equalTo:

UPDATED: If you query a pointer field, then the whereKey is modified a bit, you have to use relational queries:

let userNameQuery = PFQuery(className: "THE_CLASSNAME_WHERE_THE_USERS_ARE_STORED")
userNameQuery.whereKey("YOUR_COLUMN_NAME_WHERE_THE_NAME_OF_THE_USERS_ARE_STORED", equalTo: "THE_NAME_OF_THE_USER")

let findTimelineData:PFQuery = PFQuery(className:"Drives")
findTimelineData.whereKey("POINTER_COLUMN_OF_USER", matchesQuery: userNameQuery)
Sign up to request clarification or add additional context in comments.

8 Comments

so I am a little confused as to what to put in the where key paramters, Drives are my post , User is the class of users.
In your Drives class, how do you store your users? The column is just a string with the name of the user, or is it a pointer? I can tell by that. You must have some kind of relationship between the Drives and the Users tables.
yes the name of the user is in a pointer, so what would I put in the equalTo: ?
I actually set it equal to PFUser.currentuser() works like a charm. Just a follow up question, I will need to create a new view on clicking other users to present there profiles, because this current view only works for the current users profile?
Sorry, that was an android query... I Corrected it. To the second query: yes, it can be done. Now, you have to use relational queries, because there is no such thing this time as PFUser.currentUser(). But if you use queries like in my updated answer, then you just have to update your fields where you presents the information about the user.
|

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.