I’m using the iOS SDK and don’t see a clear and easy way to add a related child record. For this discussion assume a Service object with a one to many relationship to a 0…* set of Provider objects. I’ve already created the relation in the Developer portal (Data) in the service object defining the relationship.
I have a valid Service object that I’ve retrieved using the PersistanceService, what do I to add a single new related Provider object?
fyi, I’ve looked at the documentation, however, they details are buried in the method calls that aren’t in the documentation.
The example on the following page show how to do that:
Assuming that a Service aggregates an instance of Provider, all you need to do is to set a property in Service and then save that instance.
Ok, it was way too easy.
- The documentation couldn’t get me to make the leap, to the idea, the backendless persistanceService would go through my object’s NSArray property, figure out the class type of the collection, determine its relation, send it to the server and create the new data row. Even looking at the documentation after I have it working, the example doesn’t communicate this to me. Below is simpler and hopefully will help the next user of the system, as follows:
The .h file of the Service is
@interface Service : NSObject
@property (nonatomic, strong) NSMutableArray * providers;
The .m file for the add (assuming existing instance of Service *service and the backendless relation is setup on the backend) code snippet is:
//where provider is the record/row to be added
// response and error blocks removed for brevity
[backendless.persistenceService save:service response:nil error:nil];
The backendless.persistenceService iterated through the providers array of the service object and added the new provider(s) to the related table on the server. It just worked.
Very nice and Thank you!
Thanks, Peter, we will clarify it in the doc.