使用指针在解析中查询行(iOS) [英] Query row in Parse using Pointer (ios)
问题描述
我正在尝试从Parse中的ComparablePhotos类中获取一行数据.但是,我想从ComparablePhotos中获得的唯一一行是其指针的列"Parent"与我拥有的字符串变量markerObjectId(例如inI9tJ8x7)具有相同的objectId(在NewLog中).我将在ComparablePhotos中使用简单的查询,其中键"Parent"等于markerObjectId,但是Parent是一个指针,而不是字符串.
如何从ComparablePhotos中获取行,其指针列"Parent"的NewLog objectId与markerObjectId相同? 类似的东西,例如ComparablePhotos行的Parent.objectId == markerObjectId,是将该行存储到变量中吗?
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?
Parse中的ComparablePhotos类. 父母"列是一个指针.
ComparablePhotos class in Parse. "Parent" column is a pointer.
NewLogClass.指针指向此处.
NewLogClass. The pointer points 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)
}
推荐答案
您当前的代码:
var picquery = PFQuery(className:"ComparablePhotos")
picquery.selectKeys(["objectId", "Images", "LocationType", "Parent"])
picquery.includeKey("Parent.objectId")
picquery.orderByAscending("createdAt")
- 为
ComparablePhotos
创建查询
- 询问是否要返回一组有限的数据字段(
selectKeys
) - 要求将关联对象(错误地)包含在响应中(
includeKey
) - 订购结果
- 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
您真正想要的是在响应中获取完整的对象详细信息,并按指定的父对象进行过滤.为此,您需要为拥有的父对象ID详细信息创建一个PFObject
(请参阅objectWithoutDataWithClassName:objectId:
),然后使用whereKey:equalTo:
.
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")
这篇关于使用指针在解析中查询行(iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!