You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
setInstanceProperty fails comparison on objects or custom types with objects #517
.save() will only persist to the database if saved() returns false.
Unfortunately, in the above example when we set x to 5, the code on line 453 isn't called.
And even if it was (eg, by doing p = item.position; item.position = null; item.position = p) the comparison still wouldn't return true because value points to the same object in memory as opts.data[key] so we'd be comparing it to itself.
The solutions I can see are:
Always assume object properties have changed
When saving, fetch all Object properties from the database and compare to what we have
Keep a shadow copy of all instance data and do a comparison when calling save()
Allow something like item.save({ force: true }, ...) and maybe a global setting for this
Add item.markAsDirty('position')
Number 1 goes against the principle of least surprise.
Number 2 would result in extra queries, negatively impacting speed.
Number 3 would double memory usage - problematic if a property is storing a Buffer() of a large file.
Number 4 & 5 is rather manual.
I'm leaning towards number 4 and/or 5 but it's not exactly a nice solution..
Activity
dxg commentedon Jun 4, 2014
This problem is harder to solve than it seems.
I tried the above as well as a few other things, and nothing worked.
.save()will only persist to the database ifsaved()returns false.Unfortunately, in the above example when we set x to 5, the code on line 453 isn't called.
And even if it was (eg, by doing
p = item.position; item.position = null; item.position = p) the comparison still wouldn't return true becausevaluepoints to the same object in memory asopts.data[key]so we'd be comparing it to itself.The solutions I can see are:
save()item.save({ force: true }, ...)and maybe a global setting for thisitem.markAsDirty('position')Number 1 goes against the principle of least surprise.
Number 2 would result in extra queries, negatively impacting speed.
Number 3 would double memory usage - problematic if a property is storing a Buffer() of a large file.
Number 4 & 5 is rather manual.
I'm leaning towards number 4 and/or 5 but it's not exactly a nice solution..
kapouer commentedon Jun 4, 2014
(or variants)
dxg commentedon Jun 4, 2014
That sounds better than my ideas.
Add Instance.set() #517
dxg commentedon Jun 5, 2014
We now have:
set()will only mark the object as dirty if you are changing the value. Ifxwas2and you set it to2, it won't affect dirty state.Published as version 2.1.15.
kapouer commentedon Jun 5, 2014
that's wonderful, thank you
kapouer commentedon Sep 10, 2014
The only missing thing now is a mention of that in the docs...