-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setInstanceProperty fails comparison on objects or custom types with objects #517
Comments
This problem is harder to solve than it seems. var Place = db.define('place', {
position: { type: 'object' }
});
...
Place.create({ position: { x: 2, y: 3 } }, ...);
Place.get(1, function (err, item) {
console.log(item.saved()); // "true"
item.position.x = 5;
console.log(item.saved()); // "true"
})
Unfortunately, in the above example when we set x to 5, the code on line 453 isn't called. The solutions I can see are:
Number 1 goes against the principle of least surprise. I'm leaning towards number 4 and/or 5 but it's not exactly a nice solution.. |
|
That sounds better than my ideas. |
We now have: item.set('position.x', 2)
item.set(['position','x'], 2) // in case you have objects like { "a.b" : 4 }
item.markAsDirty('position')
Published as version 2.1.15. |
that's wonderful, thank you |
The only missing thing now is a mention of that in the docs... |
Hi,
the comparison
if (opts.data[key] !== value) {
at https://github.com/dresende/node-orm2/blob/38e76722/lib/Instance.js#L453 will never be true when modifying a property of a column that is an object. The horrible workaround is:i suggest to improve the comparison when the value is an object:
so a thorough comparison is done in case of equality of objects.
The text was updated successfully, but these errors were encountered: