Skip to content

Commit 35ab44c

Browse files
committed
Fixes #165.
1 parent 95b305b commit 35ab44c

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
###### Backwards compatible bug fixes
1212
- #156 - cached findAll pending query doesn't get removed sometimes
13+
- #165 - DS.hasChanges() reports changes after loading relations
1314

1415
##### 1.0.0-rc.1 - 03 September 2014
1516

dist/angular-data.js

+5
Original file line numberDiff line numberDiff line change
@@ -4570,6 +4570,11 @@ function changes(resourceName, id) {
45704570
});
45714571
diff[name] = DS.utils.pick(diff[name], toKeep);
45724572
});
4573+
DS.utils.forEach(DS.definitions[resourceName].relationFields, function (field) {
4574+
delete diff.added[field];
4575+
delete diff.removed[field];
4576+
delete diff.changed[field];
4577+
});
45734578
return diff;
45744579
}
45754580
}

dist/angular-data.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datastore/sync_methods/changes.js

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ function changes(resourceName, id) {
5858
});
5959
diff[name] = DS.utils.pick(diff[name], toKeep);
6060
});
61+
DS.utils.forEach(DS.definitions[resourceName].relationFields, function (field) {
62+
delete diff.added[field];
63+
delete diff.removed[field];
64+
delete diff.changed[field];
65+
});
6166
return diff;
6267
}
6368
}

test/integration/datastore/sync_methods/hasChanges.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('DS.hasChanges(resourceName, id)', function () {
3333
assert.isTrue(DS.hasChanges('post', 5));
3434
});
3535
it('should return false for resources with defined methods', function () {
36-
var Person = DS.defineResource({
36+
DS.defineResource({
3737
name: 'person',
3838
methods: {
3939
fullName: function () {
@@ -50,7 +50,7 @@ describe('DS.hasChanges(resourceName, id)', function () {
5050

5151
assert.isFalse(DS.hasChanges('person', 1));
5252
});
53-
it('should return false after loading relations', function() {
53+
it('should return false after loading relations', function () {
5454
DS.inject('user', user10);
5555

5656
$httpBackend.expectGET('http://test.angular-cache.com/organization/14?userId=10').respond(200, organization14);
@@ -61,7 +61,7 @@ describe('DS.hasChanges(resourceName, id)', function () {
6161
]);
6262
$httpBackend.expectGET('http://test.angular-cache.com/profile?userId=10').respond(200, profile15);
6363

64-
DS.loadRelations('user', 10, ['comment', 'profile', 'organization'], { params: { approvedBy: 10 } }).then(function (user) {
64+
DS.loadRelations('user', 10, ['comment', 'profile', 'organization'], { params: { approvedBy: 10 } }).then(function () {
6565
assert.isFalse(DS.hasChanges('user', 10));
6666
}, fail);
6767

@@ -71,7 +71,7 @@ describe('DS.hasChanges(resourceName, id)', function () {
7171
DS.inject('comment', comment19);
7272
$httpBackend.expectGET('http://test.angular-cache.com/user/20').respond(200, user20);
7373
$httpBackend.expectGET('http://test.angular-cache.com/user/19').respond(200, user19);
74-
DS.loadRelations('comment', 19, ['user']).then(function (comment) {
74+
DS.loadRelations('comment', 19, ['user']).then(function () {
7575
assert.isFalse(DS.hasChanges('comment', 19));
7676
}, fail);
7777
$httpBackend.flush();

0 commit comments

Comments
 (0)