简体   繁体   English

从Android中的Parse.com检索指针数据

[英]Retrieving pointer data from Parse.com in Android

I'm trying to retrieve the data from a pointer in my parse.com database from the class User which field is "companyId" Pointer Company (It gets the company objectId from the class Company) to add that data in another table called Note into a field called companyId when creating an object. 我正在尝试从我的parse.com数据库中的一个指针中检索数据,该类来自用户,该字段是“companyId”指针公司(它从公司类获取公司objectId)将该数据添加到名为Note的另一个表中创建对象时名为companyId的字段。

This is my parse.com database: 这是我的parse.com数据库:

Class Name: User 班级名称:用户
objectId String|companyId Pointer Company|username String |password String objectId String | companyId Pointer Company | username String | password String

Class Name: Note objectId String| 类名:注释objectId String | companyId String |text String companyId String | text String

I've look for solutions and I don't find anyone as I don't know how to retrieve the companyId value as it is a Pointer. 我寻找解决方案,我找不到任何人,因为我不知道如何检索companyId值,因为它是一个指针。

Thanks in advance for any repply. 提前感谢您的任何回报。

EDIT: Problem solved, below there is how it worked for me and other way of solving it by "bigdee94". 编辑:问题解决了,下面有它如何为我和其他解决方法“bigdee94”。

Thanks! 谢谢!

Carlos, you can try this : - 卡洛斯,你可以试试这个: -
According to the docs, in order to call relational data from pointer columns you can use the include() method. 根据文档,为了从指针列调用关系数据,您可以使用include()方法。

For example:- 例如:-

ParseQuery<ParseObject> userQuery = ParseUser.getQuery();
userQuery.include("companyId");
userQuery.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException e) {
   if (e == null) {
      // userObjects retrieved successfully
      ParseObject companyIdObject = (ParseObject) objects.get("companyObjectIdColumn");
   } else {
      Log.d("objects", "Error: " + e.getMessage());
   }
});



Where companyObjectIdColumn is the objectId column in you Company table(class) and 其中companyObjectIdColumn是您Company表(类)和中的objectId
objects is the queried list of objects objects是查询的对象列表
PS: you can make ParseObject companyIdObject a global variable so that you can access it from any where. PS:你可以使ParseObject companyIdObject成为一个全局变量,以便你可以从任何地方访问它。

One mate helped me and here is how we solved it: 一位伴侣帮助了我,这就是我们如何解决它:

Note n = new Note();
ParseUser user = ParseUser.getCurrentUser();
ParseObject userObj= user.getParseObject("companyId");
note.put("companyId", userObj.getObjectId().toString());

I founded kinda tricky as if you do try as: 我创建了有点棘手,好像你尝试:

Note n = new Note();
ParseUser user = ParseUser.getCurrentUser();
user.getParseUser("companyId");

It won't give the data in the field, I believe you get the memory access where the data is. 它不会在现场提供数据,我相信你可以获得数据所在的内存访问。

Thanks for your time, hope this helps more people! 感谢您的时间,希望这有助于更多的人!

I have created pointer object and i retrieved from that easily ..Below code 我已经创建了指针对象,我很容易从中检索..Below代码

 final ProgressDialog progress = new ProgressDialog(this);
    progress.setMessage("Loading ...");
    progress.setCancelable(false);
    progress.show();
    ParseGeoPoint point = new ParseGeoPoint(l1, l2);
    ParseUser user = ParseUser.getCurrentUser();
    ParseObject shop = new ParseObject("ShopLocations");
    shop.put("locationName", locname.getText().toString());
    shop.put("pin", Integer.parseInt(setpin.getText().toString()) );
    shop.put("location", point);
    shop.put("menu", ParseUser.getCurrentUser()); // this is poniter object creation in User table
    shop.put("business", ParseUser.getCurrentUser()); // this is another pointer 
    shop.put("userobjectId", user.getObjectId());
    shop.saveInBackground();
    shop.saveInBackground(new SaveCallback() {

        @Override
        public void done(ParseException e) {
            // TODO Auto-generated method stub
            progress.dismiss();
            if (e == null) {
                Toast.makeText(Createloctaion.this, "success", Toast.LENGTH_SHORT).show();
                // success
            } else {
                customToast(e.getMessage());
            }
        }
    });

Below code for retrieving pointer object : 下面是检索指针对象的代码:

 if(ParseUser.getCurrentUser()!=null) {
        ParseQuery<ParseObject> query = ParseQuery.getQuery("ShopLocations");
        query.whereEqualTo("menu", ParseUser.getCurrentUser());
        query.whereEqualTo("business",ParseUser.getCurrentUser());
        query.whereEqualTo("userobjectId",ParseUser.getCurrentUser().getObjectId());
        query.findInBackground(new FindCallback<ParseObject>() {
            public void done(List<ParseObject> object, ParseException e) {
                if (e == null) {

                    if (object.size() > 0) {
                    for (ParseObject user : object) {

                        String chkbank = user.getString("locationName");
                        Toast.makeText(Dashboard.this, ""+chkbank, Toast.LENGTH_SHORT).show();
                    }
                    } else {
                    // Handle the exception
                    }
                } else {
                    Toast.makeText(Dashboard.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();

                }
            }
        });

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM