简体   繁体   中英

Ember Data - TypeError: Object has no method 'eachRelationship'

So, I'm trying to build routes in my Ember application dynamically with data from an API endpoint, /categories , with Ember Data. In order to do this, I'm adding a didLoad method to my model, which is called by the controller and set to a property of that controller. I map the route to my router, and all that works fine. The real trouble starts when I try to set up a controller with a content property set by data from the server retrieved by findQuery.

This is the error:

TypeError {} "Object /categories/548/feeds has no method 'eachRelationship'"

This is the code:

window.categoryRoutes = [];

App.Categories = DS.Model.extend({
  CATEGORYAFFINITY: DS.attr('boolean'),
  CATEGORYID: DS.attr('number'),
  CATEGORYNAME: DS.attr('string'),
  CATEGORYLINK: function () {
    var safeUrl = urlsafe(this.get('CATEGORYNAME'));
    categoryRoutes.push(safeUrl);
    return safeUrl;
  }.property('CATEGORYNAME'),
  didLoad: function () {
    var categoryLink = this.get('CATEGORYLINK');
    var categoryId = this.get('CATEGORYID');

    App.Router.map(function () {
      this.resource(categoryLink, function () {
        // some routes
      });
    });

    App[Ember.String.classify(categoryLink) + 'Route'] = Ember.Route.extend({
      setupController: function(controller, model) {
        // source of error
        this.controllerFor(categoryLink).set(
          'content',
          this.store.findQuery('/categories/' + categoryId + '/feeds', {
            appid: 'abc123def456',
            lat: 39.75,
            long: -105
          })
        );
      }
    });
  }
});

Any 'halp' is appreciated!

Also, if I'm doing this completely wrong, and there's a more Ember-like way to do this, I'd like to know.

I figured this out. I got this error because I was passing in a string instead of a real 'type' from the App.Helpers object to an extract method in some custom RESTAdapter code I had overridden.

The solution is to pass in the corresponding model helper in App.Helpers using my custom type name.

Something like this in the overridden RESTAdapter.serializer.extractMany method:

var reference = this.extractRecordRepresentation(loader, App.Helpers[root], objects[i]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM