alekseykulikov / backbone-offline

[Deprecated] Allows your Backbone.js app to work offline
MIT License
720 stars 56 forks source link

Fetch a simple Model ? #38

Open dousylanse opened 11 years ago

dousylanse commented 11 years ago

I am trying to fetch a simple model (not a collection). I've added the updated_at field and storage field on my PhotoModel :

var model = Backbone.Model.extend( {
    urlRoot:function() {
        return "eleves/" + this.get('personId')+"/photo";
    },
    initialize: function() {
        this.on('change',
                function(){
                    this.updated_at = new Date();
                }, this);
        this.storage = new Offline.Storage("photo", this);
    }
} );

Then trying to fetch it: photo = new PhotoModel({personId:personId}); photo.fetch();

Problem : Object [object Object] has no method 'reset' backbone.offline-0.9.10.js:279

I've inspected a little the offline code. line 12 : it's the first fetch so my model doesn't have id => store.findAll line 279 : response is correct : a json object (a single one, not a table) and _this.collection.items seems to be my PhotoModel so doesn't have a reset function.

My question :

Is Backbone.offline able to work with simple model or does it work only with collection ?

Thank you for your work,

Regards

alekseykulikov commented 11 years ago

It well tested with collections, need to investigate more to play with model. Marked your question as a bug.

valerianrossigneux commented 11 years ago

@dousylanse did you manage to make it work with models ?

dousylanse commented 11 years ago

I leave the framework backbone to use angular instead. I'm sorry but i didn't make it work.

paynecodes commented 11 years ago

Hmm... I'm just now realizing that I can't persist models to localStorage. I'm not expert on Backbone yet, so I'll do my best to report back with a solution. In the meantime, if anyone can offer up some suggestions, I'd be grateful.