是否可以將Parse在相關字段上返回的字段限制爲所請求的對象?解析 - 限制在包含關係上返回的字段
Parse docs解釋瞭如何通過將字段名稱列表傳遞給keys
屬性來限制GET請求返回的字段。
You can restrict the fields returned by passing
keys
a comma-separated list. To retrieve documents that contain only thescore
andplayerName
fields (and also special built-in fields such asobjectId
,createdAt
, andupdatedAt
):
curl -X GET \
-H "X-Parse-Application-Id: [APP_KEY]" \
-H "X-Parse-REST-API-Key: [REST_KEY]" \
-G \
--data-urlencode 'keys=score,playerName' \
https://api.parse.com/1/classes/GameScore
因此,這將返回我的GameScore
對象只存在於score
和playerName
領域。我對GameScore
對象的其他字段不感興趣。
解析還允許您通過將關係名稱傳遞給includes
屬性來包含關係對象中的數據。因此,假設我有一個User
,它與GameScore
類的關係通過名爲gameScore
的字段關聯。
curl -X GET \
-H "X-Parse-Application-Id: [APP_KEY]" \
-H "X-Parse-REST-API-Key: [REST_KEY]" \
-G \
--data-urlencode 'include=gameScore' \
https://api.parse.com/1/classes/User
這將返回gameScore
對象中存在的User
和所有的領域。
我的問題是,我可以將二者結合起來,以使一個User
GET請求,包括:gameScore
關係,但限制的領域包括gameScore
對象返回,以便它只返回score
場?
我希望是這樣工作的:
curl -X GET \
-H "X-Parse-Application-Id: [APP_KEY]" \
-H "X-Parse-REST-API-Key: [REST_KEY]" \
-G \
--data-urlencode 'keys=gameScore.score' \
--data-urlencode 'include=gameScore' \
https://api.parse.com/1/classes/User
不幸的是,我得到一個錯誤返回指出
{"code":105,"error":"invalid field name: gameScore.score"}
由此我推測,這是不可能限制在包括關係領域?
嘗試使用'include = gameScore.score keys = gameScore'或者可能沒有'keys'字段。 – knshn
我不認爲這是支持的。我很好奇爲什麼這個功能對你很重要。你想節省網絡帶寬嗎? – sheki
原因之一是API調用服務器,我猜間接帶寬。我可以解決這個問題。我只是想在看到之前我是否錯過了任何東西。 – Justyn