我有一個PFObject
,Account
,它包含一個User
的數組,它們是PFUsers
的子類。 User
然後有一個NSDictonary
屬性,allowableApps
,這是一個NSDictionary
的數組,其中他們的數組包含PFObject
s。PFObject上的關係查詢
所以,作爲一個結構:
帳戶
var users: [User]
指向....
用戶
// Each key is an array of AllowApp
var allowableApps: NSMutableDictionary
指向...
AllowableApp
var appName: String
var appURL: String
var isAllowed: Bool
我想在一個查詢來獲取所有這些關係到AllowableApp
。我試過使用這樣的.includeKey
:
accountQuery?.includeKey("users")
accountQuery?.includeKey("allowableApps")
哪沒有工作。我也試過:
accountQuery?.includeKey("users.allowableApps.appName")
accountQuery?.includeKey("users.allowableApps.appURL")
accountQuery?.includeKey("users.allowableApps.isAllowed")
我嘗試填充所有的AllowableApp
對象UITableView
,但是我得到這個錯誤:
Key "appName" has no data. Call fetchIfNeeded before getting its value.
我的理解,我需要獲取所有的他們在嘗試訪問appName
財產之前。 (我試圖設置cellForRowAtIndexPath
)。
這裏是我完整的查詢:
let currentUser = User.currentUser()
let accountQuery = Account.query()
accountQuery?.whereKey("primaryUser", equalTo: currentUser!)
accountQuery?.includeKey("users.allowableApps")
accountQuery?.getFirstObjectInBackgroundWithBlock({ (account, error) in
if (error != nil) {
completion(users: nil, error: error)
}
else {
let users = (account as? Account)!.users
completion(users: users, error: nil)
}
})
我的想法,現在是剛剛通過的所有AllowableApp
對象的循環中調用viewDidAppear
fetchInBackgroundWithBlock
。然後一旦他們全部加載,我重新加載表格數據。
這似乎真的很混亂和一個共同的問題。有沒有更好的解決方案,我只是沒有看到?
嘿感謝您的回覆!如果有意義的話,我的結構更多的是'Account' - >'Users' - >'AllowableApps'。此外,我正在使用'NSMutableDictionary',因爲他們的鍵是我的表中的節標題視圖。我想我理論上可以有一個'AppCategory',它是一個'PFObject',它有一個'AllowableApps'數組,但它看起來很健壯,只是持有一個類別名稱。 – random
嗨,是的,允許的應用程序應該在用戶下,我想我的縮進現在工作得很好:)(我會更新我的答案)。無論如何,請根據答案嘗試更改您的代碼,因爲我指的是與您相同的結構。 –
我已更新我的問題以獲取正在運行的完整查詢。當我嘗試你的建議代碼時,我得到一個錯誤「只能包含指針字段」? – random