0

I am working on parse.com and updating current user data. I just want to update the current user information in another data for example "UserInfo" table, in which I want to put some updated values.

Code snippet for current user is given below:

ParseUser user = ParseUser.getCurrentUser();
user.put("firstName", fName.getText().toString());
user.put("lastName", lName.getText().toString());
user.put("email", mailText.getText().toString());
user.put("contactNumber", mobileText.getText().toString());
/*user.put("dob", medCond.getText().toString());
user.put("lastName", medication.getText().toString());
user.put("lastName", docInfo.getText().toString());*/
user.saveInBackground(new SaveCallback() {
    @Override
    public void done(ParseException e) {
        //  dismissLoadingDialog();
        if (e == null) {
            Toast.makeText(getApplicationContext(), "User Profile Has Been Updated!",
                           Toast.LENGTH_SHORT).show();
        } else {
            Logs.e(getClass().getName(), e.toString());
            Toast.makeText(getApplicationContext(), "Exception/n"+e,
                           Toast.LENGTH_SHORT).show();
            //  howMessage(e.getMessage());
        }
    }
});

But I want to update few values in my another table also. The following code is making every new entry in data bases. I want to make only an update not creation of new row.

final ParseObject update = new ParseObject("UserInfo");

update.saveInBackground(new SaveCallback() {
    @Override
    public void done(ParseException arg0) {
        // TODO Auto-generated method stub
        update.put("blood", spinnerOsversions.getSelectedItem().toString());
        update.put("doc", "");
        update.put("medicate", "ldldm");
        update.put("medical", "cdlmldm");
        update.put("medicalCond", "lalalla");
        update.put("allergy", "Twice A Day");
        update.saveInBackground();
    }
});

2 Answers 2

2

I am not very familiar with Parse but I imagine if you add the userId as a primary key to the UserInfo table, when trying to save, it should update that tuple instead of creating a new one due to the primary key constraint.

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

Comments

1

Before you can update you need to retrieve the object first. Either by objectId or another query:

ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");

// Retrieve the object by id
query.getInBackground("xWMyZ4YEGZ", new GetCallback<ParseObject>() {
  public void done(ParseObject gameScore, ParseException e) {
    if (e == null) {
      // Now let's update it with some new data. In this case, only cheatMode and score
      // will get sent to the Parse Cloud. playerName hasn't changed.
      gameScore.put("score", 1338);
      gameScore.put("cheatMode", true);
      gameScore.saveInBackground();
    }
  }
});

Parse.com documentation

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.