TypeError: Cannot read property 'type' of undefined

I get this error TypeError: Cannot read property 'type' of undefined from a this.store.query('record-type', { id : someId } call. I get a 200 reponse from the backend with the same JSON format that I get elsewhere in my app, like this

{
"id": int,
"attr1": "string",
"attr2: "string",
etc.
}

but I can’t access the object in ember. Reading a bit around it seems this might be related to a serializer issue, but I a little bit lost here. I don’t understand why in that specific case I would need to serialize whereas I don’t need to do it with the other models in my app, nor exactly how serializer works, even after reading the doc on it.

Here is my model

import DS from 'ember-data';
const { Model, attr, belongsTo } = DS;

export default Model.extend({
  autoClose: attr('boolean'),
  capaRequired: attr('boolean'),
  carNumber: attr('string'),
  conclusion: attr('string'),
  dispositionId: attr('number'),
  dispositionName: attr('string'),
  impactInfo: attr('string'),
  instructions: attr('string'),
  issueType: belongsTo('issue-type'),
  needsConfirmation: attr('boolean'),
  priority: attr('string')
});

Anyone has any idea what I am doing wrong?

Thanks!

query expects an array response, so i’m guessing that’s part of your problem. You could try queryRecord, or if this is the format that your API uses for fetching singular records (instead of something like /recordType/:id then you could customize your adapter and just use store.findRecord

Thank you very much for the fast reply!

And you are right. With queryRecord, everything works. I was under the false impression that you could not pass a query object to queryRecord, but after your answer I went to re-read the doc and it says

As in the case of store.query() , a query object can also be passed to store.queryRecord() and is available for the adapter’s queryRecord() to use to qualify the request.

Again, thanks a lot!

Glad you got it working! Sometimes fitting the right ember data paradigm to your API can be weird.