Have a Model where I want to be able to log the devicetypes of a connection by doing this:
var connections = DataLayer.context.ConnectionSet.filter(function(item) {
return item.Id == id;
}, {id: 1});
connections.forEach(function(item) {
console.log(item.Sender.Device.DeviceType);
});
item.Sender.Device.DeviceType
results in this error:
Uncaught RangeError: Maximum call stack size exceeded
This is my model:
$data.Entity.extend('SubliminalData.Connection', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'Sender': { 'type':'SubliminalData.DevicePort','required':true },
'Receiver': { 'type':'SubliminalData.DevicePort','required':true }
});
$data.Entity.extend('SubliminalData.Device', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'DeviceType': { 'type':'Edm.String','nullable':false,'required':true }
});
$data.Entity.extend('SubliminalData.Port', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true }
});
$data.Entity.extend('SubliminalData.DevicePort', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'Device': { 'type':'SubliminalData.Device','required':true },
'Port': { 'type':'SubliminalData.Port','required':true }
});
Why is this giving me a maximum call exception and how can I fix it? I couldn't find it.
--UPDATE--
I have been trying to get it work lately and I have changed my model so that I have backwards navigation properties. It makes more sense now, but now I have another problem.
New model:
$data.Entity.extend('SubliminalData.Connection', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'Sender': { 'type':'SubliminalData.DevicePort','required':true,'inverseProperty':'SendingConnections' },
'Receiver': { 'type':'SubliminalData.DevicePort','required':true,'inverseProperty':'ReceivingConnections' }
});
$data.Entity.extend('SubliminalData.Device', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'DeviceType': { 'type':'Edm.String','nullable':false,'required':true },
'DevicePorts': { 'type':'Array','elementType':'SubliminalData.DevicePort','inverseProperty':'Device' }
});
$data.Entity.extend('SubliminalData.Port', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'PortType': { 'type':'Edm.String','nullable':false,'required':true },
'DevicePorts': { 'type':'Array','elementType':'SubliminalData.DevicePort','inverseProperty':'Port' }
});
$data.Entity.extend('SubliminalData.DevicePort', {
'Id': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'Device': { 'type':'SubliminalData.Device','required':true,'inverseProperty':'DevicePorts' },
'Port': { 'type':'SubliminalData.Port','required':true,'inverseProperty':'DevicePorts' },
'SendingConnections': { 'type':'Array','elementType':'SubliminalData.Connection','inverseProperty':'Sender' },
'ReceivingConnections': { 'type':'Array','elementType':'SubliminalData.Connection','inverseProperty':'Receiver' }
});
$data.EntityContext.extend('DataLayer.SubliminalDataContainer', {
'ConnectionSet': { type: $data.EntitySet, elementType: SubliminalData.Connection },
'DeviceSet': { type: $data.EntitySet, elementType: SubliminalData.Device },
'PortSet': { type: $data.EntitySet, elementType: SubliminalData.Port },
'DevicePortSet': { type: $data.EntitySet, elementType: SubliminalData.DevicePort }
});
$data.generatedContexts = $data.generatedContexts || [];
$data.generatedContexts.push(DataLayer.SubliminalDataContainer);
/*Context Instance*/
DataLayer.context = new DataLayer.SubliminalDataContainer( { name:'oData', oDataServiceHost: 'http://localhost:57703/WcfDataService1.svc' });
My new problem is this:
var connections = DataLayer.context.ConnectionSet.filter(function(item) {
return item.Id == id;
}, {id: 1});
connections.forEach(function(item) {
l(item); //works great!
l(item.Sender); //undefined :[
});
Why is my Sender undefined? I thought I understood JayData, but I'm to believe I don't.
Your code looks ok, we think that you get this error from other part of your code, most probably from a recursive function call. Can you create a jsfiddle with your code so we can test it ?