2014-07-11 29 views
3

是否可以將Parse在相關字段上返回的字段限制爲所請求的對象?解析 - 限制在包含關係上返回的字段

Parse docs解釋瞭如何通過將字段名稱列表傳遞給keys屬性來限制GET請求返回的字段。

You can restrict the fields returned by passing keys a comma-separated list. To retrieve documents that contain only the score and playerName fields (and also special built-in fields such as objectId , createdAt , and updatedAt):

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對象只存在於scoreplayerName領域。我對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"}

由此我推測,這是不可能限制在包括關係領域?

+0

嘗試使用'include = gameScore.score keys = gameScore'或者可能沒有'keys'字段。 – knshn

+0

我不認爲這是支持的。我很好奇爲什麼這個功能對你很重要。你想節省網絡帶寬嗎? – sheki

+0

原因之一是API調用服務器,我猜間接帶寬。我可以解決這個問題。我只是想在看到之前我是否錯過了任何東西。 – Justyn

回答

0

我最終的解決方案是編寫一個自定義雲代碼方法,在將字段返回給客戶端之前將其刪除。