How to clean dirty fields in Parse object?

84 views
Skip to first unread message

ali öksüz

unread,
Mar 12, 2020, 7:03:09 AM3/12/20
to Back4App
I disabled all class level permissions for my parse object. Only way to change objects is call cloud function(and cloud function uses masterkey). However I sometimes use client side code to show current situation.

If an int filed is equal to zero.

parseObject.get("count")
//prints 0


I used increment method in android sdk (But this will never be saved because I disabled all CLPs and I never call save() function.)
parseObject.increment("count")//This is in android sdk



I call cloud function(Cloud function uses master key and actually increases that field.

parseObject.increment("count")

parseObject
.save(null,{useMasterKey});


After that If I refresh parse object increment operations includes dirty one

parseObject.fetch()
parseObject
.get("count")
//Prints 2 in android. But It should print 1.Its because increment method in android sdk is still there and waits to be saved.
How to clean parse object?



ali öksüz

unread,
Mar 18, 2020, 3:58:47 AM3/18/20
to Back4App
I solved it by keeping object dirty. Its a "dirty" way but it works.

I copy value of necessary field to another field then set that copied field to actual filed in android sdk

const tpL = postList.map(object => ({
    
...object.toJSON(),

    count2: object.get("count")

    

  
}));

Then İn android sdk I do this:

parseObject.setCount(parseObject.getCount2());

nat...@back4app.com

unread,
Jul 3, 2020, 1:54:10 PM7/3/20
to Back4App
Hi,

thanks for sharing your solution with the community.

Another option is that on Cloud Code, you manually set the amount which is going to be saved. Something like:

increment("count", 1)


Once it is configured, you will always add only one to the count column.

Regards,
Reply all
Reply to author
Forward
0 new messages