使用iOS Parse SDK
設置新PFObject作爲另一個新的PFObject的鍵值,我可以成功地創建一個新的PFObject A
並將其設置爲另一個新PFOBject B
值:解析 - 使用REST API
PFObject * objectA = [PFObject objectWithClassName:@"objectA"];
[objectA setValue:@"Test Text" forKey:@"text"];
PFObject * objectB = [PFObject objectWithClassName:@"objectB"];
[objectB setValue:objectA forKey:@"objectA"];
當我執行[PFObject saveAll:(NSArray*)objects]
時,Parse將爲objectA
生成objectId
,並將其設置爲objectB
上的密鑰中的指針值。
我該怎麼用REST API (PYTHON)
來做到這一點。從文檔,看來我必須出示在關鍵指針傳遞時,作爲一種價值爲我的類objectB
如下:
{"__type": "Pointer",
"className": "objectA",
"objectId":objectA.get('objectId')}
然而,當我創建一個新的objectA
,該objectId
還不存在。
這是我的Python代碼:
def generateFakeMessages():
messageFactory = MessageFactory(retrieveUsers())
appKeys = {
"X-Parse-Application-Id": "XXXX",
"X-Parse-REST-API-Key": "XXXX",
"Content-Type": "application/json"}
mList = []
objectA = messageFactory.fakeMessage()
arrayOfObjectBs = messageFactory.fakeRecipients()
mList.append({
"method": "POST",
"path": "/1/classes/testMessageClass",
"body": objectA
})
for objectB in arrayOfObjectBs:
objectB['objectAPointer'] = {
"__type": "Pointer",
"className": "testMessageClass",
"objectId": objectA.get('objectId')
}
mList.append({
"method": "POST",
"path": "/1/classes/recipients",
"body": objectB
})
requests = {"requests":mList}
connection = httplib.HTTPSConnection('api.parse.com', 443)
connection.connect()
connection.request('POST', '/1/batch', json.dumps(requests), appKeys)
result = json.loads(connection.getresponse().read())
print result
我加了我以前的代碼。 – blackirishman