I am playing with breezejs, and I have the problem that a computed knockout observable is not getting updated. Let me explain with a made-up example:
I have an entity (Session) with a one-to-many relation to another entity (Speaker). I fetch all Sessions with all related Speakers using the expand function in breezejs:
breeze.EntityQuery.from('Sessions').expand('Speakers');
On the breeze manager I am configuring a computed observable in the entity constructor:
var mgr = new breeze.EntityManager(config.remoteServiceName);
mgr.metadataStore.registerEntityTypeCtor('Session', null, sessionInitializer);
function sessionInitializer(session) {
session.hasOldSpeaker = ko.computed(function () {
for (var i = 0; i < session.speakers.length; i++) {
var speaker = session.speakers[i];
if (speaker.age() > 40) {
return true;
}
}
return false;
});
}
I can then listen on this observable in the view:
<span data-bind="visible: session.hasOldSpeaker">....</span>
Now I have a button that can remove the old speaker from a session, so that we no longer have any old speakers. I make a normal ajax request to do this, because it is not just updating the database, some other work must also be done, so I don't think I can do this through breeze. Anyway, after the work is done I tell breeze to refresh the entity:
var refreshQuery = breeze.EntityQuery.fromEntities(session).expand('Speakers');
manager.executeQuery(refreshQuery);
The refresh seems to work OK, as the list of related speakers for the session is now empty - but the view does not update to hide the span above.
Does anybody know why the computed binding is not updated?
If I refresh the page, then it correctly hides the span.
Update
After testing with marking all speakers for a session as deleted using Breeze's entityAspect.setDeleted, I can see that the knockout binding works as expected. So I think the problem is in the way I refresh the session entity. Maybe someone have a better way of using breeze like this? - It is not just a database update, I need to kick off some Work on the server as well. What is the best way to do this with Breeze?