I have a Model user set to be like this:
User = Backbone.Model.extend({
urlRoot: '/users',
defaults: {
id: '',
username: '',
password: ''
},
idAttribute: '_id',
initialize: function () {
console.log('User initiated');
}
});
And Collection to be like this:
var Users = Backbone.Collection.extend({
url: "/users",
model: User,
});
Users = new Users();
Then when I'm trying to get the models in my view using
Users.fetch()
, I'm only getting back one result in the "collection" array no matter how many results I have on the backend.
However, after I remove the idAttribute: '_id' from Model User, I get the exact number of results as the backend.
Does anyone know why this is happening?
p.s. As I went into the console, it seems that Users.fetch() was fired up the same amount of times as the number of users I have (each time the callback collection has only 1 model in it). So basically the last call overrides all previous ones and shows only the last result.
But I still have no idea what really is going on.