Updating specified object saves, but creates extra objects

Hello, when I try to update a One to many relation object it saves it, but it also creates several extra objects.


 func addComment() {
 
 
 self.backendless.userService.getPersistentUser()
 
 let user = self.backendless.userService.currentUser
 
 let comments = backendless.persistenceService.of(Comments().ofClass())
 var dataStore = backendless.data.of(Posts.ofClass())
 
 var newComment = Comments()
 newComment.CommentText = "Yada Yada"
 newComment.ownerId = user.objectId
 newComment.Author = user
 
 newComment = comments.save(newComment) as! Comments
 if error == nil {
 print("Comment Saved: \(newComment.CommentText)")
 dataStore.findID(
 "F6DDF0BF-5EBC-142E-FFC8-D213A5E0E700",
 response: { (result: AnyObject!) -> Void in
 let LookingForPosting = result as! Posts
 LookingForPosting.CommentsWithPost.append(newComment)
 dataStore.save(
 LookingForPosting,
 response: { (result: AnyObject!) -> Void in
 let PostingTo = result as! Posts
 print("Post has been saved: \(PostingTo.PostText)")
 
 },
 error: { (fault: Fault!) -> Void in
 print("Server reported an error (1): \(fault)")
 })
 
 
 print("Post has been found: \(LookingForPosting.objectId)")
 },
 error: { (fault: Fault!) -> Void in
 print("Server reported an error (2): \(fault)")
 }) 
 
 }
 else {
 print("Server reported an error: \(error)")
 }

}

Data Struct


class Posts : NSObject {
 
 var Author: BackendlessUser?
 var GroupPostBelongsTo: Groups?
 var CommentsWithPost = [Comments]()
 var PostText: String?
 var PostVoteCount: Int = 0
 var ownerId: String?
 var objectId: String?
 var imageURL: String?
}

class Comments : NSObject {
 var Author: BackendlessUser?
 var PostCommentBelongsTo: Posts?
 var CommentText: String?
 var CommentVoteCount: Int = 0
 var ownerId: String?
 var objectId: String?
 var imageURL: String?
}

A new object will be created if it does not have a value for the objectId property. The value must be assigned by Backendless when the object was originally persisted.

Mark

In JAVA, what does “not have a value” mean? Null or empty string “”?

// retrieve object synchronously
Contact firstContact = Backendless.Persistence.of( Contact.class ).findFirst();
firstContact.ID="";
// save new object synchronously
  Contact savedContact = Backendless.Persistence.save( firstContact);

That would be null

Then would be?

firstContact.objectId=null;

If you do not assign null, it would be the default value in Java for any new object.