Closed
Description
DS.lastModified will change when a distant object gets loaded which makes it hard to detect changes for a specific object.
DS.defineResource({
name: 'user',
endpoint: 'users',
relations: {
hasMany: {
post: {
localField: 'posts',
foreignKey: 'userId'
}
}
}
});
DS.defineResource({
name: 'post',
endpoint: 'posts',
relations: {
belongsTo: {
user: {
parent: true,
localKey: 'userId',
localField: 'user'
}
},
hasMany: {
comment: {
localField: 'comments',
foreignKey: 'postId'
}
}
}
});
DS.defineResource({
name: 'comment',
endpoint: 'comments',
relations: {
belongsTo: {
post: {
parent: true,
localKey: 'postId',
localField: 'post'
}
}
}
});
var user = DS.get('user', 1);
/*
Load all the users posts with DS.loadRelations
Load all comments of each post with DS.loadRelations
*/
// Look for changes in user 1
$scope.$watch(function () {
return DS.lastModified('user', 1);
}, function () {
console.log("User 1 has changed");
});
// Load a comment which belongs to a post which in turn belongs to user 1
DS.find('comment',1,{bypassCache:true}); // This will trigger the change in user 1
This makes it very hard to know when user 1 is updated. lastModified should probably only change when its own properties are changed (name and additions/deletions to its posts collection).