jashkenas / backbone

Give your JS App some Backbone with Models, Views, Collections, and Events
http://backbonejs.org
MIT License
28.09k stars 5.39k forks source link

fetch should not execute if id is not set; otherwise it gets the whole collection #4191

Closed brian3t closed 6 years ago

brian3t commented 6 years ago

Consider this case

var app.my_book = new Backbone.Model({ url_root: 'https://myserver/v1/books'); app.my_book.fetch(); // I forgot to set the book's id before fetching

Now app.my_book contains the list of all the books from REST server. This is because fetch was called without an id.

Suggest: if id is not set, fetch should return null and does nothing.

Thanks.

jashkenas commented 6 years ago

Some models only have URLs, and not ids.

brian3t commented 6 years ago

Ok thanks. I ended up extending the Model, but I guess it's just me then. Keep up the good work!