解析:如何从本地数据存储中获取Relation(… fromLocalDatastore())?

我正在开发一个应用程序作为学习,我使用Parse(parse.com)作为数据源。

我正在解析我的类的所有对象并保存到具有Parse的本地商店。 以下执行下载之一的代码段:

public void noticia_getOrUpdate(boolean isUpdate) throws ParseException { ParseQuery query = new ParseQuery(Noticia.class); query.orderByDescending("createdAt"); List lNoticias = null; try { if (isUpdate) { lNoticias = query.whereGreaterThan("updatedAt", this.sPref.ultimaAtualizacao_noticia()).find(); if (!lNoticias.isEmpty()) ParseObject.pinAllInBackground(lNoticias); } else { query.whereEqualTo("ativo", true); lNoticias = query.find(); for (Noticia noticia : lNoticias) { if (noticia.getUpdatedAt().getTime() > this.sPref.ultimaAtualizacao_noticia().getTime()) this.sPref.atualiza_noticia(noticia.getUpdatedAt()); } ParseObject.pinAllInBackground(lNoticias); this.sPref.atualiza_isUpdate(true); } } catch (ParseException e) { e.printStackTrace(); } } 

问题是我正在下载我的所有类,一个是文件类型,是一个用作我的新闻图像的文件(“Noticia”)。 我可以下载并存储所有现场数据存储,但无法使用以下代码进行恢复:

 public static byte[] NoticiaMidiaRelation(Noticia noticia) { try { ParseRelation relation = noticia.getImagem(); Midia midia = relation.getQuery().fromLocalDatastore.whereEqualTo("ativo", true).getFirst(); if (midia != null && midia.getFileData() != null) return midia.getFileData(); } catch (ParseException e) { e.printStackTrace(); } return null; } 

如果退出“fromLocalDatastore”查询,他会搜索服务器并正确地提供文件,但不想再追求它,因为如上所述,已经有相同的图像存储在本地数据存储中。

另一种方法是获得媒体ID之间的关系,之后执行搜索比较本地商店中的ObjectId,但我认为属性“父”没有办法。 但如果有的话,可以用作解决方案。

你不能根据文件:

默认情况下,在获取对象时,不会获取相关的ParseObjects

有一些解决方法,但它们可能不实用,因为根据我的理解,当你调用getFirst() ,你的“Notica”类中每个ParseObject的关系中只有一个图像。 在这种情况下,使用指针将是一个更好的决定,但默认情况下不会提取它们,但它们被缓存到LocalDatastore。 您需要将以下代码添加到查询中以获取Pointer对象。

 query.include("your_column_key");