如何查询在Parse中设置为指向其他表的指针的列的值 [英] How to query value of column that is set as pointer to other table in Parse

查看:212
本文介绍了如何查询在Parse中设置为指向其他表的指针的列的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用使用解析。我想查询一个表,该列设置为指向其他表的指针。以下是查询:

I am using Parse for my app. I want to query a table with column that set to be a pointer to other table. Here is the query:

ParseQuery query = new ParseQuery("CategoryAttribute");
        query.whereEqualTo("categoryId", categoryId);
        query.findInBackground(new FindCallback() {
            @Override
            public void done(List<ParseObject> categoryAttributes, ParseException e) {
                if (e == null) {
                    for (int i = 0; i < categoryAttributes.size(); i++){
                        String atributeCategoryId = categoryAttributes.get(i).getString("categoryId");
                        String attributeKey  = categoryAttributes.get(i).getString("attributeKey");
                        String attributeValue   = categoryAttributes.get(i).getString("attributeValue");

                        setCategoryAtributeRow(atributeCategoryId, attributeKey, attributeValue);
                    }
                } else {
                    Log.d("score", "Error: " + e.getMessage());
                }
            }
        });

所以 categoryId 列是指向其他表。其他列工作正常。
我试图扫描API和指南,但找不到所需的解决方案。非常感谢帮助!

So the categoryId column is a pointer to other table. Other columns work fine. I tried to scan the API and the guides but couldn't find needed solution. Help would be much appreciated!

推荐答案

以下是此解决方案的解决方案:

Here is the solution to this one:

首先你需要从表的类型创建 ParseObject

First you need to create a ParseObject from the type of your table:

ParseObject sale = ParseObject.createParseObject("Sale"); 

然后你需要从 ParseObject 获取结果:

Then you need to get the ParseObject from the result:

sale = result.getParseObject(pointer_field);

现在你可以从 sale 拉出任何字段正如你通常所做的那样,例如:

Now you can pull from sale any field that it has just as you would do it normally, for example:

sale.getString("some_field")

注意:
当您进行查询时,必须包含指针字段,如果您希望能够在返回查询后从中提取数据。结果:

Note: When you are doing your query you must to include the pointer field if you want to be able to extract the data from it after the query will be returned. The result:

query.include("pointer_field")

希望有所帮助

这篇关于如何查询在Parse中设置为指向其他表的指针的列的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆