2012-07-25 226 views
2

這個問題過濾數據存儲的結果早有答案爲Python: How to get all records from GAE datastore with particular parent?由母公司

我怎麼做進去嗎?我想這樣做:

t := new(TagRecord) 
k, err := datastore.DecodeKey(r.URL.Path[1:]) 
... 
_, err = datastore.NewQuery("TagRecord"). 
    Filter("Parent =", k). 
    Order("-CreatedAt"). 
    Limit(1). 
    Run(c).Next(t) 

...但是這並出現以下錯誤悲慘的失敗了:

datastore: query has no more results 

當我嘗試過濾其它特性,包括硬編碼到過濾器和那些通過URL傳遞的查詢會正確運行並使用適當的屬性填充t。用什麼羞恥的簡單來解決我的問題?

回答

2

什麼讓你在這裏是父母查詢不使用過濾器()。相反,您使用的ancestor constraint

q := datastore.NewQuery("TagRecord"). 
    Ancestor(k). 
    Order("-CreatedAt"). 
    Limit(1) 

// etc... 
0

請確保您還定義索引這個特定的查詢和上傳索引配置文件