out_sid3r
out_sid3r

Reputation: 1028

How to save entity using Objectify and keep some values untoutch

Objectify framework makes it easier to interact with Google Datastore and I'd like to know if it was possible to ofy().save() an entity but only change in the database the values that aren't null.

Because I make a new instance of the entity and I don't have access to all its attributes values (data comes from a POST and things like relation keys are missing) I wanted to just change store/edit the attributes received (like a SQL Update).

I tried using @IgnoreSave(IfNull.class) but after saving and checking the saved entry the attributes that weren't set at save() time are set to null and I loose relationship with other entities.

Upvotes: 2

Views: 878

Answers (1)

Michael
Michael

Reputation: 1397

If I understand you correctly you have a entity A which is already saved. You would like to change an attribute of A (lets say A.b) to something but keep everything else the same? What you should do is a ofy().get(A), change A.b and then save(A).

If you make a new entity A (from the constructor) then that entity will overwrite the currently saved entity.

Upvotes: 1

Related Questions