"likes" in a social app

Dear Backendlesses,

trying to let one user “like” another users’ post.

at first I thought about getting the other users’ “likes” property which is a users one to many, adding the user that is pressing the like, and retrieving the property again and show the sum of it (which is now greater in 1 than before).

BUT - and it could be a major bug - what if two users press “like” in my oh so popular app together ? my logic tells me that one user will be overwritten by the other when the Async task is completed.

so my question is : how do I add something to a users’ property without retrieving the property ?

thanks! love you guys.
Gil.

how do I add something to a users' property without retrieving the property ?

ArrayList<BackendlessUser> likesCollection = new ArrayList<BackendlessUser>();
likesCollection.add( someUserObject );
userObject.setProperty( “likes”, likesCollection );

Please do not take this code literally, it shows a general guideline.

Thanks Mark, I didn’t know we could do that!
Will this aproach work on removing from a collection as well?

Yes, you can use the same approach to remove objects from a collection.

Thanks Mark, will do.

Dear Mark, it works in overwriting the property “likes”, and it doesn’t add to it. so every “like” deletes the other users’ “likes”.

is there a way in Backendless to add and not overwriting a property ? so that all the users could add to the property, without overwriting each other.

Instead of creating a new collection, retrieve the related objects from the server and add a new object to the existing collection.

yes that’s what I’m doing, but I’m sure that it’s not “good practice” to do that…