1

I am trying to get a row of data from the class, ComparablePhotos in Parse. However, the only row from ComparablePhotos I want to get, is the row whose pointer, column "Parent", has the same objectId (in NewLog) as a string variable I have, markerObjectId, ex: inI9tJ8x7. I would use the simple query in ComparablePhotos where key "Parent" is equal to markerObjectId, but Parent is a pointer, and not a string.

How do I grab the row from ComparablePhotos whos whose pointer, column "Parent", has the same NewLog objectId as a markerObjectId?  Something along the lines like if the ComparablePhotos row's Parent.objectId == markerObjectId, store that row into a variable?

ComparablePhotos class in Parse. "Parent" column is a pointer. enter image description here

NewLogClass. The pointer points here. enter image description here

Here is my code:

    var newLogObjectsArray: [PFObject] = [PFObject]()

    //newLogObjectId is a string im comparing to, ex: inI9tJ8x7
    newLogObjectId = objectIdArray[markerIndex]

    var picquery = PFQuery(className:"ComparablePhotos")
    picquery.selectKeys(["objectId", "Images", "LocationType", "Parent"])
    picquery.includeKey("Parent.objectId")
    picquery.orderByAscending("createdAt")
    picquery.findObjectsInBackgroundWithBlock { (NewLog, error) -> Void in

        //Here prints are all our rows from the class, ComparablePhotos.
        println("NewLog")

        if let NewLog = NewLog as? [PFObject] {
            for log in NewLog {
                //Here are all our rows from the class, NewLog.
                var ParseNewLogClass: PFObject = (log["Parent"] as? PFObject)!
                self.newLogObjectsArray.append(ParseNewLogClass)
            }
4
  • 1
    Have you tried comparing the pointer to an object instead of the string id of the object? Commented Jul 23, 2015 at 6:46
  • No I have not.. How would I do that? Commented Jul 23, 2015 at 6:47
  • 1
    Your query doesn't actually have a check of the parent currently. And you would create an object placeholder with the id (there is an api for that) Commented Jul 23, 2015 at 6:51
  • I thought it does check Parent.. I have picquery.selectKeys and one of them is "Parent"... I'm sorry I don't follow, this is my first app in Parse and in swift, so I am very new. Could you please provide a code sample? Commented Jul 23, 2015 at 7:02

1 Answer 1

2

Your current code:

var picquery = PFQuery(className:"ComparablePhotos")
picquery.selectKeys(["objectId", "Images", "LocationType", "Parent"])
picquery.includeKey("Parent.objectId")
picquery.orderByAscending("createdAt")
  • creates a query for ComparablePhotos
  • asks for a limited set of data fields to be returned (selectKeys)
  • asks for an associated object to be included in the response (incorrectly) (includeKey)
  • orders the results

What you actually want is to get the full object details in the response and to filter by a specified parent. To do that you need to create a PFObject for the parent object id details you have (see objectWithoutDataWithClassName:objectId:) and then use whereKey:equalTo:.

var picquery = PFQuery(className:"ComparablePhotos")
picquery.includeKey("Parent")
picquery.whereKey("Parent", equalTo:parentObject)
picquery.orderByAscending("createdAt")
Sign up to request clarification or add additional context in comments.

6 Comments

I have attempted and I feel I am almost at success. I have created a PFObject, pointer. However, I am generating an error: "Cannot invoke whereKey with an argument list of type, String"... What am I doing wrong?
Code: let pointer = PFObject(withoutDataWithClassName:"ComparablePhotos", objectId: newLogObjectId) picquery.whereKey("Parent") picquery.includeKey("Parent", equalTo:pointer) picquery.orderByAscending("createdAt")
did you by chance mix up the whereKey and the includeKey in your code?
THANK YOU WAIN! I cannot emphasize how much I appreciate your help. I was stuck on this for a week, and was almost about to give up. You are appreciated!
P.S the whereKey and includeKey are mixed up in your code, so maybe you could update it so it doesnt confuse others that look at this :D
|

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.