How to call ParseObject before it returns ObjectId (saved)?

ParseObject only gets the ObjectId after saving it. If I was offline at the time of creation and could not save the object, how can I refer to it while offline?

For example, how to set a postId comment when I don't know post Id yet?

I was considering the possibility of creating a separate TempId attribute in my extended ParseObject , which I can put an exclusively locally known identifier that it can refer to until it has the proper object identifier, but this is the best choice. there is?

I am worried about the following:

  • Double processing
  • Maintaining all the callbacks needed to make sure that I am updating the correct object in the correct order.

Thanks!

0
android
source share
1 answer

Here is my rule of thumb: I think objects, not object identifiers.

 var post = // ... this is a real object, not an id. it can be new var comment = // ... this is a real object, not an id. it can be new // posts might have many comments by keeping an array of pointers called "comments" post.add("comments", comment); // or posts might have many comments by keeping a relation called "comments" post.relation("comments").add(comment); 

After that, the parent side of the relationship can be saved, as well as unsaved children:

 post.save().then(function(savedPost) { // savedPost now has savedPost.id, but who cares? // if comments is an array of pointers: // savedPost.get("comments") now has comments with ids, but again, we don't need them. // if comments is a relation: return savedPost.get("comments").query.find(); }).then(function(comments) { // comments is an array of objects with ids, but again, if I find // myself needing those ids, its a clue that my design is weak }); 
0
source share

All Articles