使用指针(ios)在Parse中查询行

时间:2015-07-23 06:31:31

标签: ios swift parse-platform

我正在尝试从类中获取一行数据,Parse中的ComparablePhotos。但是,我想要获得的ComparablePhotos唯一的一行是指针,列“Parent”,具有与我所拥有的字符串变量相同的objectId(在NewLog中),markerObjectId,ex:inI9tJ8x7。我会在ComparablePhotos中使用简单查询,其中键“Parent”等于markerObjectId,但Parent是一个指针,而不是一个字符串。

如何从ComparablePhotos中获取行,其指针“Parent”具有与markerObjectId相同的NewLog objectId?像是ComparablePhotos行的Parent.objectId == markerObjectId一样,将该行存储到变量中?

Parse中的ComparablePhotos类。 “父”列是一个指针。 enter image description here

NewLogClass。指针指向这里。 enter image description here

这是我的代码:

    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)
            }

1 个答案:

答案 0 :(得分:2)

您当前的代码:

var picquery = PFQuery(className:"ComparablePhotos")
picquery.selectKeys(["objectId", "Images", "LocationType", "Parent"])
picquery.includeKey("Parent.objectId")
picquery.orderByAscending("createdAt")
  • ComparablePhotos
  • 创建查询
  • 要求返回一组有限的数据字段(selectKeys
  • 要求相关对象包含在响应中(错误地)(includeKey
  • 订购结果

您真正想要的是获取响应中的完整对象详细信息并按指定的父级进行过滤。为此,您需要为您拥有的父对象ID详细信息创建PFObject(请参阅objectWithoutDataWithClassName:objectId:),然后使用whereKey:equalTo:

var picquery = PFQuery(className:"ComparablePhotos")
picquery.includeKey("Parent")
picquery.whereKey("Parent", equalTo:parentObject)
picquery.orderByAscending("createdAt")