如何从多个Parse.com表/类中检索数据

时间:2014-11-11 12:32:54

标签: android mysql parse-platform

我有两个表(Classes):

StudentInformation:列有RollNumber,地址,姓名,学校 StudentMarks:列RollNumber,Marks1,Marks2,Marks3

我已经能够将单个表单中的数据同时保存到这两个表单中,但是在检索到列表视图或任何其他视图时无法获得如何查询的信息

'返回行(从两个表一起),其中卷号= 1234'/'返回行(从两个表一起),其中Marks2> 50'

我正在使用Parse.com后端Android版 请帮助 感谢

1 个答案:

答案 0 :(得分:7)

首先,在ListView中显示的UI方面由ParseQueryAdapter提供。 https://parse.com/docs/android_guide#ui-queryadapter

关于查询,我认为您不能以您想要的方式连接表。相反,您可以在StudentMarks中创建一个指向StudentInformation的指针。

然后你可以查询类似的东西:

ParseQuery<ParseObject> query = ParseQuery.getQuery("StudentMarks");
query.include('studentInformation'); // include the pointer to get StudentInformation
query.whereEqualTo("RollNumber", 1234);
query.whereGreaterThan("Marks2", 50);
... // perform query

在结果中,StudentInformation将如下所示:

List<ParseObject> objects; // the result from the query
ParseObject studentMark = objects.get(0); // example using first object
ParseObject studentInformation = studentMark.get("studentInformation");
String studentName = studentInformation.get("name");
String studentAddress = studentInformation.get("address");
... // etc

或者您也可以在StudentInformation上存储StudentMarks的关系,只是为了让您知道这也是一个选项,尽管我觉得它不符合您当前的需要以及上面提到的解决方案。