emberjs / data

A lightweight reactive data library for web applications. Designed over composable primitives.
https://api.emberjs.com/ember-data/release
Other
3.03k stars 1.33k forks source link

Didn't get a warning for a misspelled payload item in relationships hash #4727

Open rstudner opened 7 years ago

rstudner commented 7 years ago

code that should have given me warning: https://github.com/emberjs/data/blob/master/addon/-private/system/store.js#L2353-L2358

my result payload:

        "similiar-alerts": {
          "links": {
            "related": "/api/v1/alerts/8deb2777-0714-42c3-b2bd-b0925b72d2a5/similiar-alerts"
          }
        },
        "vendor-alerts": {
          "links": {
            "related": "/api/v1/alerts/8deb2777-0714-42c3-b2bd-b0925b72d2a5/vendor-alerts"
          }
        },

my model object:

import Ember from 'ember';
import DS from 'ember-data';
const { computed } = Ember;
const { Model, attr, hasMany } = DS;

export default Model.extend({
  name: attr(),
  similarAlerts: hasMany('alert'),
  vendorAlerts: hasMany('vendor-alert'),
});

Note that in the payload it is similiar and in the model object similar.

runspired commented 7 years ago

Thanks!

runspired commented 7 years ago

The reason we don’t hit them (I suspect) is that we copy over only known attributes and relationships in the serializer to the final payload, would need to dig in to confirm that.

so TL;DR we should have this validation layer in both places, or make sure the defaults don't remove things they don't understand so that these warnings will be encountered.