3

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.

This is my parse.com database:

Class Name: User
objectId String|companyId Pointer Company|username String |password String

Class Name: Note objectId 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.

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

Thanks!

3 Answers 3

4

Carlos, you can try this : -
According to the docs, in order to call relational data from pointer columns you can use the include() method.

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
objects is the queried list of objects
P.S: you can make ParseObject companyIdObject a global variable so that you can access it from any where.

Sign up to request clarification or add additional context in comments.

3 Comments

bigdee94, Thanks for replying but I founded an easier solution as I described below. I believe it works but if I'm not wrong with your answer I would have to make another ParseQuery to get the objectId from the table Company. Even though it might help if anyone wants to do it like that.
No @CarlosRomero, You just have to call the objectId column into another ParseObject like so, ParseObject companyIdObject = (ParseObject) objects.get("companyObjectIdColumn");. I haven't tried it though but I believe it's logically correct. I'm glad you found a simpler solution
There's no need to cast the parse object, you can just use objects.getParseObject("") opposed to what you have there
2

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!

Comments

0

I have created pointer object and i retrieved from that easily ..Below code

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

                }
            }
        });

    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.