jeromegn/Backbone.localStorage

can not fetch a model - trigger a GET

Closed this issue · 2 comments

Hey there, thanks for the brilliant plugin,
here's my code
var Job = Backbone.NestedModel.extend({
defaults:{
}
...
})

var JobCol = Backbone.Collection.extend({
model:Job,
url:"jobs",
localStorage: new Backbone.LocalStorage("jobs")
});

the problem is:
when I try to fetch the model

var job = new Job({id:id});
job.fetch()

it still trigger a GET quest,

So what would be the best way to fetch a model?

I know I can fetch the whole collection first then get the model by id:

var jobs = new JobCol();
jobs.fetch();
job = jobs.get(id);

but, do we have a way to fetch the model directly instead fetch the collection every time?

Thanks very much!

the model doesn't know the collection, you need to put the same localStorage key in the model definition, but read issue #101 and my fix to the problem