upshotsingle-page-application

upshot js change tracking in child entities


I have the following model defined in .NET:

 Public Class Request
  <Key()>
  Public Property RequestId As String
  Public Property Description As String
  Public Property InfoCards As List(Of InfoCard)
End Class

Public Class InfoCard
  <Key()>
  Public Property InfocardId As String
  Public Property Description As String
  Public Property RequestId As String
End Class

The ReqeuestId property on the InfoCard is so that EF Code First can generate the db. I then use the UpshotContext helper to generate the JavaScript model like so:

Html.UpshotContext(bufferChanges:= true) _
  .DataSource(Of UpshotTest.UpshotTest.RequestController)(Function(x) x.GetRequests()) _
  .ClientMapping(Of UpshotTest.Models.Request)("Request") _
  .ClientMapping(Of UpshotTest.Models.InfoCard)("InfoCard")

This generates all models nicely, and when I call refresh on the upshot dataSource, the data is retrieved as expected.

The problem I am facing is when I attempt to modify a property of a child object (e.q. Request.InfoCards(0).Description). Changing that value will trigger the change in the InfoCard, but not in the Request entity. So, calling Request.IsUpdated() will return false, whilst calling Request.InfoCards(0).IsUpdated() will return true.

Does upshot not know how to track changes in child entities? Or is it a problem with the mappings on the client side? So far I have tried several mappings:

The mappings seem correct with all approaches, except the parent entity is not aware of modifications done in its children. Is child tracking even possible?


Solution

  • Okay, I found the issue in the end. As it turns out, this behavior was reproducible when a hierarchy of 3 nested entities existed (i.e. Request -> InfoCard -> InfoField. Modifying a value of the InfoField did not reflect in the parent entity.

    After many hours of upshot debugging, I found the culprit to be the _addTrackingRecursive method in upshot.js. Replacing the obs.track(obj, this._getTracker(), this._entityType); call to obs.track(obj, this._getTracker(), type); solved the nested change tracking issue.