【发布时间】:2014-07-16 06:31:59
【问题描述】:
在Parse SDK relation 部分,它给出了以下代码:
// Create the post
ParseObject myPost = new ParseObject("Post");
myPost.put("title", "I'm Hungry");
myPost.put("content", "Where should we go for lunch?");
// Create the comment
ParseObject myComment = new ParseObject("Comment");
myComment.put("content", "Let's do Sushirrito.");
// Add a relation between the Post and Comment
myComment.put("parent", myPost);
// This will save both myPost and myComment
myComment.saveInBackground();
这很棒,而且有效。如果您将“MyComment”固定到本地数据存储区,它看起来甚至还保存了“MyPost”对象。不过似乎有一个问题,那就是父对象(帖子)没有被固定。
我有以下代码:
ParseQuery<ParseObject> bjjHistoryCheck = ParseQuery.getQuery("bjjMatchMoves");
// bjjHistoryCheck.fromPin("bjjMatches");
// bjjHistoryCheck.whereEqualTo("className", "bjjMatches");
bjjHistoryCheck.fromLocalDatastore();
// bjjHistoryCheck.whereEqualTo("matchLoser", "Debbie Sanchez");
bjjHistoryCheck.countInBackground(new CountCallback() {
public void done(int count, ParseException e) {
Log.i("parse Exception", e.getMessage());<---------
long e1 = new DateTime().getMillis();
Log.i("time to find user matches: ",
String.valueOf(e1 - s1) + " ms + count: " + String.valueOf(count));
if (count < 1) {
noHistoryDialog();
} else {
final Intent intent = new Intent(getActivity(), Dialog_History.class);
intent.putExtra("classToShow", 1);
startActivity(intent);
}
这按预期工作,因为我固定了“bjjMatchMoves”,就像我在评论中一样,我得到了本地数据存储中有多少移动的计数。如果我用匹配(帖子)替换移动查询,那么它找不到任何东西。您可以看到许多注释掉的行...我尝试以我能想到的所有方式进行搜索...什么也没有。如果我删除 localdatastore 选项,那么它会成功找到云中的记录。
带箭头的行在 LogCat 中显示以下内容:
07-15 22:58:26.018: I/parse Exception(24145): 试图获取一个 从未保存到离线缓存的离线对象。
所以我问你们所有人......你们如何固定评论和帖子?是否可以?我现在能想到的唯一方法是一种肮脏的方法:在 Activity 首次启动时创建 Match 对象,然后立即将其保存在后台。保存后,重新检索它,然后使用输入的任何信息进行更新,并指出记录的任何移动,但如果有一种方法可以指定匹配并且移动被固定,它会更清晰。
【问题讨论】:
-
你有没有用 bjjMatches 标签固定任何东西?