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.
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
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"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With