I have a Message table which has one-to-many relation property recipients(it contains list of BackendlessUser) and so my User table has one-to-many relationship Messages.recipient (‘childOf’ type) property, which contains list of Messages
What i need is to get this property (Messages.recipient), delete certain message and save again.
How is it possible to do in code?
Thanks!
This is how it looks in console
APP_ID = "B98036D8-4C4B-8D51-FF42-E6C0E74CF800
Do you need to get messages which belong to a specific user?
if ‘User’ contains in ‘Messages.recipient’ then he receives this message, and if he delete this message then this message will be deleted from backendless console. - i have this working.
But if there is many recipients in ‘Messages.recipient’ (‘Messages’ table, ‘recipients’ property), then if specific user delete this message on device, it shouldn’t delete it from backendless console, but he should be removed from ‘Messages.recipient’ list (‘Messages’ table, ‘recipients’ property).
So i need to delete a specific user from Messages.recipient (‘Messages’ table, ‘recipients’ property) or delete specific message from ‘User’ (User table, Messages.recipient property)
To delete a user from Messages.recipient, you need to load the Messages object (with the “recipient” relation), remove the user from the recipient collection and then save the Messages object back to the server.
i tried it like this
let whereClause = "recepients.objectId = '\(user.objectId)'"
let dataQuery = BackendlessDataQuery()
dataQuery.whereClause = whereClause
backendless.data.of(Messages.ofClass()).find(dataQuery, response: { (result) in
self.messageArray = result.data as! [Messages]
print(self.messageArray)
self.tableView.reloadData()
}) { (error) in
print(error)
}
messageToPass = messageArray[indexPath.row]
var recipientArray = messageToPass.recepients
for recipt in recipientArray {
if recipt.objectId == activeUser.objectId {
let index = recipientArray.indexOf(recipt)
recipientArray.removeAtIndex(index!)
messageToPass.recepients = recipientArray
var error: Fault?
let result = backendless.data.save(messageToPass, error: &error) as? Messages
if error == nil {
print("PhoneBook havs been updated: \(result)")
}
else {
print("Server reported an error: \(error)")
}
but i get an error:
FAULT = ‘8011’ [Users can only be added as related objects by specifying their valid object ID, all other values are ignored. For creating Users please use User API.]
This looks reasonable. How long ago did you update the SDK library?
To rule out any regression, may I ask you to download the SDK from our website (not the github repo) and try the same thing with that build? Please let me know if the same use-case works.
Regards,
Mark
same thing.
Can it be because i try to save new Messages.recipient which contains other users?
As long as other users have valid objectId values, it should work
Thanks, this is very helpful. We’ll connect to your backend. in the morning and try to replicate the problem to experience it ourselves
they should have, because i didn’t touch them.
Could you attach the following screenshots:
Messages table
Messages schema
Users table schema
Thank you very much! I will be waiting for your messages
Hi Evgeny,
I was able to reproduce the problem you’re experiencing. An internal ticket has been created.
Regards,
Mark
Great to hear! Thanks for your help.
Is it possible somehow to follow progress on this ticket?
Sure, we will update this topic when the problem is fixed.
Regards,
Mark