Search code examples
javascriptbackbone.js

Backbone Collection not using it's model


I have a simple Model:

App.Models.Client = Backbone.Model.extend({});

And a simple Collection:

App.Collections.Clients = App.Collections.Base.extend({
    model: App.Models.Client,
    urlRoot: '/clients'
});

The Base collection is simple:

App.Collections.Base = Backbone.Model.extend({
    url: function() {
        return App.BaseURL + this.urlRoot;
    }
});

The problem is, when I do:

var c = new App.Collections.Clients();
c.fetch();

The objects in this collection are Object literals, not of type App.Model.Client

What am I doing wrong?


Solution

  • should it be

    App.Collections.Base = Backbone.Collection.extend({
        url: function() {
            return App.BaseURL + this.urlRoot;
        }
    });
    

    not Backbone.Model