我想知道在进行关系查询时是否可以将缓存中的解析对象与相关对象一起保存。如果我有网络,那就说我通常会在缓存中查询和固定数据。
ParseQuery<ParseObject> books = ParseQuery.getQuery("Book");
books.include("author");
books.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> books, ParseException e) {
if (e == null) {
ParseObject.unpinAllInBackground("allBooks", books, new DeleteCallback() {
public void done(ParseException e) {
if (e != null) {
// There was some error.
return;
}
// Add the latest results for this query to the cache.
ParseObject.pinAllInBackground("allBooks", books);
}
});
for (ParseObject book : books) {
String authorName = book.getParseUser("author").getString("name");
String bookTitle = book.getString("title");
}
} else {
Log.d("query error", e.toString());
}
})
})
这就是我在调用上面的查询之前最初从缓存加载数据的方法。
ParseQuery<ParseObject> books = ParseQuery.getQuery("Book");
books.fromPin("allBooks");
books.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> books, ParseException e) {
if (e == null) {
Log.d("cache results", String.valueOf(books.size()));
String authorName = book.getParseUser("author").getString("name");
String bookTitle = book.getString("title");
} else {
Log.d("cache error", e.toString());
}
}
});
问题是当我从缓存加载时,ParseUser作者的数据没有固定。我收到了这个错误。
java.lang.IllegalStateException: ParseObject has no data for 'name'. Call fetchIfNeeded() to get the data.
如何确保作者ParseUser数据也与其他数据一起固定?感谢