Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse: How to set a pointer in Android?

In my current class, say A, I have a column which is a pointer to another class, say B. Can anyone please let me know how I can set a value for this column in Android?

I have tried fetching the required row from class B as a ParseObject, and doing a:

classAObject.put("column_name",classBParseObject);

But, this is just creating an empty row in my class A, with no pointers. Any help in this regard is much appreciated.

like image 921
Faux Pas Avatar asked Aug 28 '14 18:08

Faux Pas


2 Answers

If you have the objectID of the course ID for Computer Science, then you need to save using the createWithoutData method. So let's recap: You have a Student table with a column called CourseId - that is a pointer to the Course table, not the CourseId column of the Course table. You can't point to a column, you point to a table.

So when you create a new Student object, you need to save a pointer into the CourseId column for Computer Science. Let's say the objectID of the Computer Science object in your Course table is "xyz123". You would do the following:

ParseObject student = new ParseObject("Student");
student.put("CourseId", ParseObject.createWithoutData("Course", "xyz123") );
//...set other values for the student object
student.saveInBackground();

The Parse docs has what you need and more - check out the section on relational data: https://parse.com/docs/android_guide#objects-pointers

like image 153
user2163298 Avatar answered Sep 22 '22 11:09

user2163298


If it is a custom class then use the following code (Eg : "AnotherClass" is a custom class)

classAObject.put("column_name", ParseObject.createWithoutData("AnotherClass", "abc123"));

or if it is Parse Class like User, Installations etc, use like this,

classAObject.put("column_name", ParseObject.createWithoutData(ParseUser.class, "abc123"));
like image 25
Rajesh Hegde Avatar answered Sep 26 '22 11:09

Rajesh Hegde