Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datasource (local_storage.js) does not support more than one model #14

Open
deeDude opened this issue Jul 8, 2013 · 1 comment
Open

Comments

@deeDude
Copy link

deeDude commented Jul 8, 2013

I debugged local_storage.js and found out that the method _keyForRecordType always returns "sproutcore.local.storage.undefined", meaning that the property recordType.localStorageKey placed on a model SC.Record (as in Todos.Todo model) is always undefined. Therefore, that datasource does not work when you have more than one model.

I'm using SC v1.9.2.

Cheers

@dcporter
Copy link
Member

The bug in this code looks to be simply that we define the localStorateKey property as an instance property, but try to use it as a class property. Given that we're syncing data into local storage on a per-Model basis, the class is probably the correct place for this. So in todos.js (the app's lovely monolithic file) round about line 34, you'd change this:

// Define the Todo model.
Todos.Todo = SC.Record.extend({
  title: SC.Record.attr(String),
  isDone: SC.Record.attr(Boolean, { defaultValue: false }),
  createdAt: SC.Record.attr(SC.DateTime),

  // The string used by the localStorage adapter to uniquely identify
  // this model type.
  localStorageKey: 'todo'
});

to this:

// Define the Todo model.
Todos.Todo = SC.Record.extend({
  title: SC.Record.attr(String),
  isDone: SC.Record.attr(Boolean, { defaultValue: false }),
  createdAt: SC.Record.attr(SC.DateTime),
});
Todos.Todo.mixin({
  // The string used by the localStorage adapter to uniquely identify
  // this model type.
  localStorageKey: 'todo'
});

Mind trying that and let me know how it works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants