【发布时间】:2016-03-27 04:25:17
【问题描述】:
我有一个表 UserProfile,它有一个指向相应用户表的指针列(用户)。我正在尝试构建一个简单的查询来获取用户对象的 UserProfile。但是,查询返回 nil(对象 = 我的应用程序中的用户对象):
let profileQuery = PFQuery(className: "UserProfile")
profileQuery.whereKey("user", equalTo: object)
profileQuery.includeKey("user")
profileQuery.limit = 1
profileQuery.findObjectsInBackgroundWithBlock{
(results: [PFObject]?, error: NSError?) -> Void in
if error != nil{
print(error)
} else if let results = results as? [PFObject]! {
for result in results {
self.profile = result
}
}
}
知道为什么这个查询不起作用吗?谢谢!
使用 Mazel 的解决方案更新代码:
query.findObjectsInBackgroundWithBlock {
(objects: [PFObject]?, error: NSError?) -> Void in
if error != nil {
print(error)
} else if let objects = objects as? [PFObject]! {
for object in objects {
let profileQuery = PFQuery(className: "UserProfile")
profileQuery.whereKey("user", equalTo: PFObject(outDataWithClassName: "_User", objectId: "\(object.objectId!)"))
//profileQuery.includeKey("user")
profileQuery.limit = 1
profileQuery.findObjectsInBackgroundWithBlock{
(results: [PFObject]?, error: NSError?) -> Void in
if error != nil{
print(error)
} else if let results = results as? [PFObject]! {
for result in results {
self.profile = result
}
}
}
【问题讨论】:
-
问题出在这一行 profileQuery.whereKey("user", equalTo: object) 但你没有分享什么是 object 这么难说...
-
感谢您的回复! object 是我之前在应用程序中运行的另一个查询的结果。我没有包括它,所以它不会混淆人们。 object 是来自 User 表的 PFUser。所以我希望运行另一个查询来获取该用户的 UserProfile(该用户在我的查询中称为对象)。
标签: ios swift parse-platform swift2