In your initialization use maxDataServiceVersion
instead of dataServiceVersion
.
I'm not sure why you'd need the above hack especially when using it with an unknown verb like UPDATE
http://msdn.microsoft.com/en-us/library/dd541276.aspx. In OData there are two allowed HTTP Verbs MERGE
for V2 and PATCH
for V3. Once you set maxDataServiceVersion: 3.0
JayData will send out correct PATCH
requests.
The hack your are using should be applied in a different situation, where either clients, proxies, routers don't support these two verbs. In that case you'd send a POST request instead and set the desired verb as X-HTTP-Method
. This method is often referred as verb-tunneling see e.g. http://msdn.microsoft.com/en-us/library/dd541471.aspx.
$data.initService('/odata', { maxDataServiceVersion: '3.0' }).then(function (context) {
if (!mycontext)
mycontext= context;
//this hack shouldn't be used here
// mycontext.prepareRequest = function (r) {
// if (r[0].method == "PATCH") {
// r[0].method = 'PUT';
// r[0].headers['X-HTTP-METHOD'] = 'UPDATE';
// }
// };
vm.roles = mycontext.Role.toLiveArray();
vm.users = mycontext.User.toLiveArray();
});
Update based on comment
I'd check the context via the console. Make sure ctx
is globally available e.g
window.ctx = context;
Attach something by ID e.g.
var role = ctx.Role.attachOrGet({ID: 'GUID or Int'});
role.
will give your access to the entity properties e.g. assuming a Status
property that accepts Int
role.Status = 1; //Set role.Status to 1
Last run ctx.saveChanges()
. If everything is setup correctly JayData will send a PATCH request to the /odata/Role/GUID
endpoint with the changes as JSON payload.