Closed MFlisar closed 7 years ago
Sure, there are many ways to do this. Probably the easiest is to simply call setPropertiesFromValuesStorage using only the properties you are interested in, which I imagine you could provide using your IUpdateBeforeUpdate
object:
existing.setPropertiesFromValuesStorage(item.getSetValues(), updateBeforeUpdate.whichPropertiesToSave());
If you do this though, note that the contract of markSaved
will be somewhat broken. It will still put the skipped values into the databaseValues
of the model, which is interpreted to mean "these were the last known values to exist in the database" -- which of course if some set values were skipped, they are not. Probably it's more "correct" to instead make item
take on only the values from existing
after the update has occurred, e.g. using item.clear(); item.readPropertiesFromValuesStorage(existing.getDatabaseValues())
. Of course, you will have to decide what is the most "correct" for your use case. Hope that helps!
Those set/getPropertiesFromValuesStorage
are a bit confusing imho, I don't get their meaning by reading the name just as the AbstractModel
setValues
and values
field as well. I think something like get/setPersistetValues()
and persistedValues
and notYetPersistedValues
or similar would reflect the purposes a little more, just my personal opinion though...
I think I get the idea now and can solve my problem with the tipps, thanks
This is a question, though it's too long to write a good formatted gitter post...
I'm using an extended
insertOrUpdate
method like here: https://github.com/yahoo/squidb/issues/226 that looks like following:My
updateBeforeUpdate
paramater does only do following: it callsitem.clearValue(field)
for some user fields that MAY already exist so that those already existing values are not overwritten. So far so good.Problem
After calling such an update function with a full loaded model, the model is not useable anymore, because it may have fields that were cleared.
What I want
I want to call the
updateOrInsert
function and keep all fields but be able to skip some fields from being persisted when calling this functions (BUT keep them in the model if they are in there.) Can I do this? Or do I have to extract the fields, save them in a list, save my model and reset the fields?