Widgetmaster has many widgetVersions. A widgetVersion can only have one widgetMaster.
Public Class widgetMaster
Public Property ID() As Integer
...other properties
Public Overridable Property WidgetVersions() As ICollection(Of widgetVersion)
End Class
Public Class widgetVersion
Public Property ID() As Integer
Public Property WidgetMasterID() As Integer
...other properties
Public Overridable Property WidgetMaster() As widgetMaster
End Class
My viewmodel:
var newWidget = ko.observable();
var newWidgetVersion = ko.observable();
var isSaving = ko.observable(false);
var activate = function () {
return datacontext.newWidget(newWidget),
datacontext.newWidgetVersion(newWidgetVersion).then(setNewWidgetVariables());
}
};
var setNewWidgetVariables = function() {
newWidget().groupId(globalVar.selectedGroupId());
}
var save = function () {
isSaving(true);
return datacontext.saveChanges([newWidget]).fin(complete);
function complete() {
isSaving(false);
}
};
Even though my saveChanges specifies only the newWidget entity:
return datacontext.saveChanges([newWidget]).fin(complete);
...Breeze is still adding in a child "widgetVersion" to the widgetVersions table (without any widgetMasterID set either - it's set to 0) and I don't want it to do that! Or at least if it persists, I want it to pick up the newly-added widgetMasterID.
Why does Breeze add the related entity even though I've told it to only do the master? I want to do the master, fetch the new ID, then save the widgetVersion entity with that new ID included and Breeze is stopping me doing this for some reason I don't understand.
createEntity('widgetMaster')
and then doing something like attaching the widgetVersion entity to it? Would that create the link that would automatically fill in the widgetMaster ID in the related widgetVersion entity? - TheMook