Shopify/batman — Issue #194: Batman.Model.get("all") not working consistently when using RestStorage
Author: goyox86
Created: 2011-10-24 23:10:00+00:00
State: open

Hi all!

People I'm creating a small application using Batman.js and until yesterday I was using LocalStorage for all of my models.

My code looks like this: https://gist.github.com/1310626

When I use LocalStorage everything works as expected but when I use RestStorage:

"Question.get('all').length < 1" Is always true.

But what makes me think that I'm missing something or that there is a bug in the library is that as you can see in the gist I've attach here is that when there are no questions, I create the questions and associate a set of answers to it.

I was suspecting that I was not getting properly connected to the Rails Rest Backend (I'm using Rails 3.1.1) because I was having this "Question.get('all') < 1" evaluated to true. Even with a preloaded set of questions already living in the db.

The surprise for me is that when I load the page and the controller with the code above runs it actually creates the questions and the Rails REST interface sees it and saves it to the db, So I am in effect connected via the RestStorage interface.

My question is why Question.get("all") does work with LocalStorage but not with RestStorage?

Do I am doing something wrong?

Is there a best way of loading all the records from the REST Backend? (I've used load and the same happens).
Cheers,
Jose