user1714647
user1714647

Reputation: 664

ParseObject does not create a row in table in my Database

I'm using this code to actually let the user send a questionand 4 answers (it's a long story), and storage it on my game database. This is the code I used, after seeing the docs and just the table doesn't get updated. I don't really know why

private void sendQuestion() {
    ParseUser currentUser = ParseUser.getCurrentUser();
    String role = currentUser.get("Role").toString();
    if(role.equals("Founder"))
    {
        String questionText = mQuestion.getText().toString();
        String[] answers = new String[4];
        for(int i = 0; i < 4; i++) {
            answers[i] = mAnswers[i].getText().toString();
        }
        ParseObject question = new ParseObject("Questions");
        question.put("lang", mSelectedLang);
        question.put("question", questionText);
        for(int i = 0; i < 4; i++) question.put("answer" + (i+1), answers[i]);
        question.put("enabled", true);
        question.put("from", currentUser);

        question.saveInBackground(new SaveCallback() {
            @Override
            public void done(ParseException e) {
                Log.d("MyApp", "Done");
            }
        });
    }else
        Log.d("MyApp", "Not founder");
}

This is what I get from the Logs

05-27 19:57:21.063    2307-2307/*************** D/MyApp﹕ Send question button pressed
05-27 19:57:21.530    2307-2307/*************** D/MyApp﹕ Done

Says it's done but the Table Questions is not updated, as said. Pay attention that both "lang" and "from" are relations fields, so I put there object and not simple values like Strings or Integer.

Why doesn't the table get updated?

Here you can look the official docs to save an object https://www.parse.com/docs/android/guide#objects-saving-objects

Upvotes: 0

Views: 66

Answers (2)

user1714647
user1714647

Reputation: 664

I self resolved changing the rows type from 'Relation' to 'Pointer', as I read here https://parse.com/questions/expected-relation_user-but-got-_user (didn't find it because it was asked for iOS but it's not about the wrong code).

Now it works.

Upvotes: 1

Divers
Divers

Reputation: 9569

I think you should change

question.put("from", currentUser);

with something like:

question.put("from", currentUser.getId()); // pass id of user, not object itself

Upvotes: 0

Related Questions