java 如何查询在Parse中设置为指向其他表的指针的列的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15517541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 19:53:29  来源:igfitidea点击:

How to query value of column that is set as pointer to other table in Parse

javaandroidparsingparse-platform

提问by vlio20

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

我正在为我的应用程序使用Parse。我想查询一个表,其中的列设置为指向其他表的指针。这是查询:

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());
                }
            }
        });

So the categoryIdcolumn 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!

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

回答by vlio20

Here is the solution to this one:

这是解决这个问题的方法:

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

首先,您需要根据ParseObject表的类型创建一个:

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

Then you need to get the ParseObjectfrom the result:

然后你需要ParseObject从结果中得到:

sale = result.getParseObject(pointer_field);

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

现在,您可以sale像往常一样从它具有的任何字段中提取,例如:

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")

Hope it helps

希望能帮助到你

回答by Rafael Garcia

@Akshat Agarwal, here is a example in JavaScript:

@Akshat Agarwal,这是一个 JavaScript 示例:

var parseObj = Parse.Object.extend('parseObj');

new Parse.Query(parseObj)
  .include('pointerField')
  .find(function (data) {
    data.get('pointerField').get('fieldName');
  });

回答by Inder Kumar Rathore

For iOS

对于 iOS

  PFQuery *parseQuery = [PFQuery queryWithClassName:@"MyClass"];
  [parseQuery whereKey:@"categoryId" equalTo:categoryId];
  [parseQuery includeKey:@"pinter_field"];
  [parseQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
  //
  }];