Bug repro: Repro constraint error failure
HTML
<script src="http://include.jaydata.org/1.3.1beta/jaydata.js"></script>
JavaScript
$data.Entity.extend('NorthwindModel.Category', {
'Category_ID': { key: true, type: 'Edm.Int32', nullable: false, computed: false},
'Category_Name': { type: 'Edm.String', nullable: false, required: true, maxLength: 15 },
'Description': { type: 'Edm.String', nullable: true},
'Picture': { type: 'Edm.Binary', nullable: true },
'Products': { type: 'Array', elementType: 'NorthwindModel.Product', inverseProperty: 'Category' }
});
$data.Entity.extend('NorthwindModel.Product', {
'Product_ID': { key: true, type: 'Edm.Int32', nullable: false, computed: true },
'Supplier_ID': { type: 'Edm.Int32', nullable: true },
'Category_ID': { type: 'Edm.Int32', nullable: true },
'Product_Name': { type: 'Edm.String', nullable: false, required: true, maxLength: 40 },
'English_Name': { type: 'Edm.String', nullable: true, maxLength: 40 },
'Quantity_Per_Unit': { type: 'Edm.String', nullable: true, maxLength: 20 },
'Unit_Price': { type: 'Edm.Decimal', nullable: true },
'Units_In_Stock': { type: 'Edm.Int16', nullable: true },
'Units_On_Order': { type: 'Edm.Int16', nullable: true },
'Reorder_Level': { type: 'Edm.Int16', nullable: true },
'Discontinued': { type: 'Edm.Boolean', nullable: false, required: true },
'Category': { type: 'NorthwindModel.Category', inverseProperty: 'Products' },
});
var NorthwindDB = $data.EntityContext.extend("NorthwindDB", {
Products: { type: $data.EntitySet, elementType: NorthwindModel.Product },
Categories: { type: $data.EntitySet, elementType: NorthwindModel.Category }
});
var EntityContext = new NorthwindDB({ name: 'local' });
EntityContext.onReady()
.then(function() {
var instanceofCategory = new NorthwindModel.Category();
instanceofCategory.Category_ID = 1;
instanceofCategory.Category_Name = 'x';
EntityContext.Categories.add(instanceofCategory);
EntityContext.saveChanges({
success: function() { alert('save successful'); },
error: function(reason) {
alert('b');
...