tectonic icon indicating copy to clipboard operation
tectonic copied to clipboard

Defaulting model.fields.id to undefined produces error

Open slightlytyler opened this issue 7 years ago • 3 comments

Example

import { Model } from 'tectonic';

class SomethingModel extends Model {
  static modelName = 'something';

  static fields = {
    description: undefined,
    id: undefined,
    name: undefined,
  };
}

export default SomethingModel;

results in Error: Must supply an ID field for this model. The docs provide an example with id: undefined. Is this valid or no?

slightlytyler avatar Feb 06 '17 20:02 slightlytyler

I had this problem too. Turns out I wasn't passing an id through to my query (it was misspelled in my component's props). I would expect to receive an ignoring query as it has undefined parameters error. However, my model, like yours had id: undefined and so I got Error: Must supply an ID field for this model instead.

Ideally, if we miss a parameter in our query and have id: undefined in our model we should get an error saying which parameter is missing. Error: ignoring query as it has the following undefined parameters: 'id' would be more helpful.

matthewconstantine avatar Feb 24 '17 00:02 matthewconstantine

Yep, agreed. I'll see if I can get to this bug this week.

Also, I feel as though this should be valid:

static fields: {
  id: undefined
}

which should also be fixed.

Finally, setting static idField should also fix this error.

tonyhb avatar Jul 24 '17 04:07 tonyhb

Whenever this is completed, you may want to update this documentation as we start off with errors when trying to stand up the examples from docs:

image https://tonyhb.github.io/tectonic/api-model.html

dbryand avatar Jan 08 '18 19:01 dbryand