I have stripped down my application and database context to the simplest bits. I have two tables, Maps and Markers. Many Markers exist for each map. With an existing Map, I can't seem to insert new Markers; I am getting the default error callback.
Tracing through the jaydata.js, I am getting an error in the SqLiteProvider.js file, in the exec
function. It is an SQL failure, and is attempting to insert the Map (with the primary key set) into the table, which fails. What am I doing wrong?
My Context:
$data.Entity.extend("$org.types.Marker", {
Id: { type: "int", key: true, computed: true },
Left: { type: "int", required: true },
Top: { type: "int", required: true },
Color: { type: "string", required: true },
Name: { type: "string", required: true },
Map: { type: "$org.types.Map", inverseProperty: "Markers" }
});
$data.Entity.extend("$org.types.Map", {
Id: { type: "int", key: true, computed: true },
Title: { type: "string", required: true },
Src: { type: "string", required: true },
Height: { type: "int", required: true },
Width: { type: "int", required: true },
Markers: { type: "Array", elementType: "$org.types.Marker", inverseProperty: "Map" }
});
$data.EntityContext.extend("$org.types.OrgContext", {
Maps: { type: $data.EntitySet, elementType: $org.types.Map },
Markers: { type: $data.EntitySet, elementType: $org.types.Marker },
});
var DB = new $org.types.OrgContext({ name: "webSql", databaseName: "Testing"});
My test code:
DB.Maps.single( function (map) { return map.Id == 1; }, {}, function(map) {
var marker = new $org.types.Marker({
Left: 250,
Top: 350,
Color: 'green',
Name: 'Example',
Map: map});
DB.Markers.add(marker);
DB.saveChanges(function() {
alert(marker.Id);
});
});