【问题标题】:How to query value of column that is set as pointer to other table in Parse如何查询在 Parse 中设置为指向其他表的指针的列的值
【发布时间】:2013-03-09 04:37:47
【问题描述】:

我正在为我的应用程序使用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());
                }
            }
        });

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

【问题讨论】:

  • 你找到解决办法了吗

标签: java android parsing parse-platform


【解决方案1】:

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

首先你需要根据你的表类型创建一个ParseObject

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

那么你需要从结果中得到ParseObject

sale = result.getParseObject(pointer_field);

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

sale.getString("some_field")

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

query.include("pointer_field")

希望对你有帮助

【讨论】:

  • @Jaffar Raza 这是答案
  • 你能提示一下如何使用 javascript 做到这一点吗?
  • @AkshatAgarwal,对不起,我不知道如何在 javascript 中执行此操作。但我确信它非常相似。
  • 抓不到你!!!看到我有一个指向“用户”的字段用户名,我只想用那个指针来查询它!你能推荐我吗??????
  • 他们应该将它包含在他们的文档中!很好的解决方案!
【解决方案2】:

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

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

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

【讨论】:

    【解决方案3】:

    对于 iOS

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-04
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      • 2013-05-28
      相关资源
      最近更新 更多