Skip to content

Commit

Permalink
make unsets work on queries
Browse files Browse the repository at this point in the history
  • Loading branch information
lgandecki committed May 23, 2017
1 parent 26e2697 commit 35ba865
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/RxDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,18 @@ class RxDocument {
if (newDoc[previousPropName]) {
// if we don't check inequality, it triggers an update attempt on fields that didn't really change,
// which causes problems with "readonly" fields
if (!deepEqual(this[previousPropName], newDoc[previousPropName]))
this[previousPropName] = newDoc[previousPropName];
if (!deepEqual(this._data[previousPropName], newDoc[previousPropName]))
this._data[previousPropName] = newDoc[previousPropName];

} else
delete this[previousPropName];
delete this._data[previousPropName];

});
delete newDoc._rev;
delete newDoc._id;
Object.keys(newDoc).forEach(newPropName => {
if (!deepEqual(this[newPropName], newDoc[newPropName]))
this[newPropName] = newDoc[newPropName];
if (!deepEqual(this._data[newPropName], newDoc[newPropName]))
this._data[newPropName] = newDoc[newPropName];
});
await this.save();
}
Expand Down
16 changes: 15 additions & 1 deletion test/unit/RxQuery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,21 @@ describe('RxQuery.test.js', () => {
});
});


describe('update', () => {
it('unsets a value on a query', async() => {
const c = await humansCollection.create(2);
const query = c.find();
await query.update({
$unset: {
age: ''
}
});
const docs = await query.exec();
for (let doc of docs)
assert.equal(doc._data.age, undefined);
c.database.destroy();
});
});

describe('issues', () => {
it('#157 Cannot sort on field(s) "XXX" when using the default index', async() => {
Expand Down

0 comments on commit 35ba865

Please sign in to comment.