I am using the Android SDK. I have the user added to the user table and I have the children added to the Booking table. Now when I try to set the relation, I keep getting
BackendlessException{ code: ‘1303’, message: ‘Unable to create relation. Child objects with ids ‘null’,‘null’ are not found in the related table.’ }
HashMap<String, Object> parentObject = new HashMap<String, Object>();
parentObject.put("objectId", GlobalVar.myUser.getUserObjectId());
ArrayList<Map> children = new ArrayList<Map>();
for (Booking booking : bookings_arr) {
HashMap<String, Object> childObject = new HashMap<String, Object>();
childObject.put("objectId", booking.getObjectId());
children.add(childObject);
}
ResultReturn results = new ResultReturn();
BackendlessUser user = Backendless.UserService.CurrentUser();
try {
Integer val = Backendless.Data.of(BackendlessUser.class)
.setRelation(user, "Booking", children);
I never used backendless 3. I am using the Set relation (as shown above) as per the documentation ( as far as I know). Infact the set relationship between data tables works fine. It is just for some reason from User table to data table returns the above exception
But the docs say
Integer result = Backendless.Persistence.of( “TABLE-NAME” ).setRelation( Map parentObject, String relationColumnName, Collection<Map> children );
So shouldn’t it take Collection of Maps (like any other relations adding between data tables)?
Oh wow!!! That worked!! I think I understand what’s going on here.
In order to add a relation to User Table, you can’t use Backendless.Data.of(“Users”) as it complains you have pass BackendlessUser.class.
And the fact that we are forced to that, it makes the whole thing follow the “custom class” way meaning I can no longer set relation using Map and I have to set it by passing the object.
Does this understanding make sense? Maybe it would be beneficial to add section about that in docs for the “relation with Users tables” OR enable us to use Maps with user tables to satisfy all use cases (such the case when you don’t have an object such as Booking where it maps perfectly to the table)