I am using ember-cli and ember-data 1.13.7 and JSONAPIAdapter. I use http-mock to mock data during local testing. It worked well when I used the RESTAdapter, but I ran into a problem when switching to the JSONAPIAdapter.
The problem is that the records data does not get loaded into the store and I get an error reading an undefined property.
The adpater just looks like this:
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
namespace: 'api',
});
The ajax call is this:
http://localhost:4200/api/users/1
The http-mock looks like this:
usersRouter.get('/:id', function(req, res) {
res.send({
'users': {
id: req.params.id,
firstname: "John",
lastname: "Doe",
email: "[email protected]",
mobile: "12345678",
nextAppointment: 1
}
});
});
The response looks like this:
{"users":{"id":"1","firstname":"John","lastname":"Doe","email":"[email protected]","mobile":"12345678","nextAppointment":1}}
The response data islooking good but the problem is that together with the response is the header status code of 304, and the fact that the data is not loaded into store. The object with id=1 is created, but all properties in the object are 'undefined' when I look at the stores data in the ember inspector.
Update:
The error I get is:
Error while processing route:
home.index Cannot read property '_internalModel' of undefined
TypeError: Cannot read property '_internalModel' of undefined
Update 2: It turns out the 304 is not important. The model is still not properly loaded into store when the httpcode is 200 either. I also fund that this call works fine:
http://localhost:4200/api/users
while this call fails:
http://localhost:4200/api/users/1
They return exactly the same JSON response.