Hi,
i need to be able to use the PHP SDK to add objects into a table, where each object has a one-to-one relationship to an object on another table.
ie,
Table 1: clients
Table 2: notifications
Table 2 has the one-to-one relationship to clients, and I need to be able to add new notifications for existing clients.
I can create clients OK, and retreive them OK, but I’d like to to be able to add a new notification when all I know is the client objectID - it’s a bit of a waste to make one request to get the full client object, then another to create the notification, as I already have the client objectId saved.
Is this possible?
Regards,
Andy
It is posible. Just create Client object put objectId to it, then create Notfication object and put client to it, save notification object
Hi Sergey,
Thanks for getting back to me.
I’ve just tried this. However it’s overwriting the existing client data with the null values in the server-side object. The notification is saved correctly, and it’s linked to the correct client ID, but the client data is nulled.
Any thoughts?
Regards,
Andy
Further to the above, I’ve done some more searching on the forum, and found this http://support.backendless.com/t/how-to-set-relation-in-object-without-updating-related-object
Admittedly it seems to be 7 months old, but sounds like the same problem.
Andy
OK, I think I’ve found the problem:
To create a new notification, I don’t supply the notification objectID, but I do have to supply the client object with it’s objectID. The SDK tries to do a PUT to the notification table, but in doing so errors out because you can’t put to a known object (the client).
Does that sound right? If so, what’s the solution?
Andy
Hi Andrew,
Instead of just creating a Client object and setting objectId to it, use findById call.
OK, I’ll try that Sergey. I was hoping to be able to avoid 2 round-trips to the server.
Hi,
OK, that worked. I’ll go with that for now.
Thanks
Andy